Эта функция должна работать:
function isInView(el) {
let bb = el.getBoundingClientRect();
return bb.top <= window.innerHeight && bb.bottom >= 0
&& bb.left <= window.innerWidth && bb.right >= 0;
}
Вот демоверсия:
document.onscroll = function() {
document.querySelector('.status').textContent = isInView(document.querySelector('.element')) ? 'IN' : 'OUT';
}
function isInView(el) {
let bb = el.getBoundingClientRect();
return bb.top <= window.innerHeight && bb.bottom >= 0
&& bb.left <= window.innerWidth && bb.right >= 0;
}
.before,
.element,
.after {
height: 200vh;
background: wheat;
}
.element {
background: teal;
}
.status {
position: fixed;
top: 20px;
right: 20px;
padding: 1em;
background: silver;
}
<div class="before">Before</div>
<div class="element">Element</div>
<div class="after">After</div>
<div class="status">...</div>