MaxelRus MaxelRus - 1 year ago 63
Javascript Question

Prevent 'wheel' event scrolling if element has basic scroll

I've built custom scrolling on my page through

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

Answer Source

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

window.addEventListener('wheel', function(event) {
    if ( < ) {
          // scollheight less than clientheight, means it doesn't have scrollbars ...
          // do stuff                                
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download