JavaScript - Undo the scroll event

I want to disable scrolling on one of my pages. I do not want to write

scroll(0,0) or scrollTo(0,0)

in the scroll event, which will give an "unstable" character. Could I something like

 event.preventDefault() 

to cancel an event?

+4
source share
5 answers
 document.body.style.overflow = 'hidden'; 
+5
source

The only acceptable way to prevent scrolling is to put the content inside the window. Anything else and you are pissing users.

You can also use position: fixed CSS - but still, if it is larger than the window, the rest is unsuitable, so you can also follow suggestion number 1.

+2
source

I wonder if there will be overflow: hidden; work by putting it in an html, body selector in CSS?

0
source

Create a div that fills the entire area and sets it to overflow: hidden . This way, you will never get scrollbars, and no scroll events will be generated.

0
source

This is what worked for me.

Remember the previous scroll position.

 onScroll(event){ if(blockScrollFlag){ event.target.scrollTop = prevScrollPosition; } } 
-2
source

All Articles