I don't think you can accomplish this by adding an event to the element itself. I think you'll have to add listeners to the window for any events that can possibly change which elements are in view (load, scroll, resize).
I borrowed isScrolledIntoView() from this answer
// Get your element however you'd like
let myElmement = document.getElementById('myElement');
// Loop through possible events that will bring element into view
['resize','scroll','load'].forEach( eventName => {
window.addEventListener(eventName, event => {
if (isScrolledIntoView(myElmement)) {
doYourThing();
} else {
console.log('nope');
}
});
});
// Borrowed from https://stackoverflow.com/a/22480938/12771340
function isScrolledIntoView(el) {
let rect = el.getBoundingClientRect();
let elemTop = rect.top;
let elemBottom = rect.bottom;
// Only completely visible elements return true:
let isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight);
// Partially visible elements return true:
//isVisible = elemTop < window.innerHeight && elemBottom >= 0;
return isVisible;
}