Is there a way to check if a DOM element is really visible on screen?
Meaning :
- Its not hidden (e.g: display: none, visibility: hidden)
- Its not hidden by another element
- its opacity is not 0, neither is the opacity of one of its parents.
(these are the cases i could think of)
this is what i got so far
function isVisible(el) {
//is hidden (display, visibility)
var isHidden = el.style.display == 'none' || ['collapse', 'hidden'].indexOf(el.style.visibility) == -1;
if(isHidden)
return false;
//is hidden by another element
el.scrollIntoView();
var rect = el.getBoundingClientRect();
var targetAtPos = document.elementFromPoint(rect.left, rect.top);
var isHiddenByAnother = targetAtPos != el;
if(isHiddenByAnother)
return false;
//Check opacity
}