📌  相关文章
📜  js 检查元素是否进入视图 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:49.487000             🧑  作者: Mango

代码示例1
function isInViewport(element) {
    const rect = element.getBoundingClientRect();
    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
    );
}