MaxelRus MaxelRus - 1 month ago 8
Javascript Question

Prevent 'wheel' event scrolling if element has basic scroll

I've built custom scrolling on my page through

wheel
event on
window
. However it shoots even when I want to scroll the element with basic scrollbar. How to disable
wheel
event on this element, but be able to scroll?

Answer

You can check in the event handler if the element is scrollable

window.addEventListener('wheel', function(event) {
    if ( event.target.scrollHeight < event.target.clientHeight ) {
          // scollheight less than clientheight, means it doesn't have scrollbars ...
          // do stuff                                
    }
})