SOURCE

console 命令行工具 X clear

                    
>
console
document.onscroll = function () {
   var isInView = isInViewPortOfOne(document.querySelector('#scroll4'))
   console.log('isInView:', isInView)
}

function isInViewPortOfOne (el) {
    // viewPortHeight 兼容所有浏览器写法
    const viewPortHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight 
    const offsetTop = el.offsetTop
    const scrollTop = document.documentElement.scrollTop
    const top = offsetTop - scrollTop
    console.log("offsetTop: ", offsetTop, ", scrollTop: ", scrollTop)
    console.log("getBoundingClientRect: ", el.getBoundingClientRect())
    return top <= viewPortHeight
}
<div id="scroll1">312321321</div>
<div id="scroll2">312321321</div>
<div id="scroll3">312321321</div>
<div id="scroll4">312321321</div>
div {
    height: 500px
}

#scroll1 {
    background: #333;
}

#scroll2 {
    background: #666;
}

#scroll3 {
    background: #999;
}


#scroll4 {
    background: blue;
}