📜  如果元素在视图中,则执行函数 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:45.184000             🧑  作者: Mango

代码示例1
var counter;

window.onscroll = inView;
counter = document.getElementById('counter');
function inView() {
    if (counter.getBoundingClientRect().top <= window.innerHeight) {
        console.log('IN VIEW');
    }
}