Skip to content
Advertisement

How to disable scrolling temporarily?

I’m using the scrollTo jQuery plugin and would like to know if it is somehow possible to temporarily disable scrolling on the window element through Javascript? The reason I’d like to disable scrolling is that when you scroll while scrollTo is animating, it gets really ugly 😉

Of course, I could do a $("body").css("overflow", "hidden"); and then put it back to auto when the animation stops, but it would be better if the scrollbar was still visible but inactive.

Advertisement

Answer

The scroll event cannot be canceled. But you can do it by canceling these interaction events:
Mouse & Touch scroll and Buttons associated with scrolling.

[Working demo]

JavaScript

UPDATE: fixed Chrome desktop and modern mobile browsers with passive listeners

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement