Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript - Cancel Scroll event

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?

like image 519
NLV Avatar asked Aug 04 '10 11:08

NLV


People also ask

How do I stop a scroll 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.


2 Answers

document.body.style.overflow = 'hidden';
like image 80
Marcelo Avatar answered Sep 18 '22 13:09

Marcelo


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.

like image 20
Amadan Avatar answered Sep 22 '22 13:09

Amadan