有没有办法检查屏幕上是否真的可以看到DOM元素?
意义:
(这些是我能想到的情况)
这是我到目前为止所得到的
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
}