I have a main layout block with the property overflow: auto and because of this, the scroll event is triggered only in this block, although I add a listener to the window object.
How do I add a scroll event listener to the window if I don't know the class or id of the specific block on which the event occurs?
window.addEventListener('scroll', () => {
console.log('scroll!')
});
* {
margin: 0;
padding: 0;
}
main {
height: 100vh;
overflow-y: auto;
}
div {
width: 500px;
height: 300px;
margin: 10px 0;
background: rgb(45, 62, 206);
}
<main>
<div></div>
<div></div>
<div></div>
<div></div>
</main>
