I have many elements in a webpage of my APP.
How to make it so that whenever the cursor is not hovering over any of the scrollable elements, then it will automatically target a designated element?
I have many elements in a webpage of my APP.
How to make it so that whenever the cursor is not hovering over any of the scrollable elements, then it will automatically target a designated element?
When the user uses the mouse wheel or the arrow buttons when not on any element that's scrollable (including the <body>
), no scroll event is fired. This is also the case when the user attempts to scroll up when at the very top, and when they attempt to scroll down when at the very bottom.
So, a scroll listener won't work. You probably need to instead listen for mouse wheel events instead.
You probably need:
wheel
listener on the window (so it listens to all wheel events)if (e.target.closest('.scrollable1, .scrollable2')) return;
.scrollTo
on the desired target element.