I want to disable the scroll in one of my pages. I don't want to write
scroll(0,0)
or scrollTo(0,0)
in the scroll event which will give a 'jumpy' nature. Can't I have something like
event.preventDefault()
for canceling the event?
The window. onscroll event fires when the window has been scrolled. Overriding this function and setting it to a fixed position every time the scroll happens will effectively disable the scroll effect.
document.body.style.overflow = 'hidden';
The only acceptable way of preventing scrolling is making the content fit inside the window. Anything else, and you're pissing users off.
You can also use position: fixed
CSS - but still, if it's larger than the window, the rest is unusable, so you might as well follow the suggestion #1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With