0
因此,当作为参数给出的元素完全位于视口/窗口中时,下面的代码返回true。如果元素的0%以上位于视口/窗口中,则返回true
如何将其更改为在元素的任何位或任何超过0%的元素位于视口中时返回true?
function isElementInViewport(el){
var rect = el.getBoundingClientRect();
return(
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document. documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document. documentElement.clientWidth)
);
}