MaxelRus
MaxelRus

Reputation: 305

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?

Upvotes: 0

Views: 160

Answers (1)

adeneo
adeneo

Reputation: 318182

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                                
    }
})

Upvotes: 2

Related Questions