Snippets

代码片段收集板

检查元素是否位于当前视窗(可用于lazyload, infinite scroll等常见功能)edit

日期:

作者: 小胡子哥

function isInViewport(el) {
    var rect = el.getBoundingClientRect();

    return rect.bottom > 0 &&
        rect.right > 0 &&
        rect.left < (window.innerWidth || document. documentElement.clientWidth) &&
        rect.top < (window.innerHeight || document. documentElement.clientHeight);
}

Example Usage:

window.addEventListener('scroll', function() {
    isInViewport(el);
})

标签:

loading...

这网速真是弱爆了...客官稍等,评论还在加载~