判断dom原始是否在可视区域内

isElementInViewport (el, offset = 0) {
const box = el.getBoundingClientRect(),
top = (box.top >= 0),
left = (box.left >= 0),
bottom = (box.bottom <= (window.innerHeight || document.documentElement.clientHeight) + offset),
right = (box.right <= (window.innerWidth || document.documentElement.clientWidth) + offset)
return (top && left && bottom && right)
}
posted @ 2019-03-23 15:03  小小lomo  阅读(1764)  评论(0编辑  收藏  举报