7

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?

Bill the Lizard
  • 386,424
  • 207
  • 554
  • 861
NLV
  • 20,611
  • 36
  • 116
  • 181
  • See http://stackoverflow.com/questions/1459676/prevent-scroll-bubbling-from-element-to-window/1460020#1460020 – Crescent Fresh Aug 04 '10 at 11:38
  • http://stackoverflow.com/questions/4770025/how-to-disable-scrolling-temporarily although that is to temporarily disable scrolling, you can set it to permanently disable it. You should use that instead of using overflow: hidden because Chrome has a bug that you can still scroll on overflow: hidden pages using the mousewheel, arrow keys, pgup and pgdn keys, and touch scrolling if you're on a touch device. The accepted answer in that link provides a way that effectively disables it. – markasoftware Jul 22 '13 at 17:36

4 Answers4

5
document.body.style.overflow = 'hidden';
Bill the Lizard
  • 386,424
  • 207
  • 554
  • 861
Marcelo
  • 9,277
  • 3
  • 33
  • 40
3

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.

Amadan
  • 179,482
  • 20
  • 216
  • 275
  • There actually are many uses for cutting off content. My site uses css 3d transforms, and for some reason a useless part of it extends 10-20 pixels beyond the end of the page. – markasoftware Jul 22 '13 at 17:39
  • Quite the blanket statement Amadan. In my case, I want to shut down the auto scrolling (which is "pissing off" my users.) This occurs when elements from the list are added / removed. Please don't assume that a particular technique is no good, just because this particular use case could be criticized. – redevill Aug 20 '20 at 22:22
0

I wonder if overflow: hidden; will work by putting it on the html, body selector in CSS?

dsamarin
  • 313
  • 2
  • 6
0

Create a div that fills the whole area and set that to overflow: hidden. That way, you will never get scroll bars and no scroll events will be created.

Aaron Digulla
  • 310,263
  • 103
  • 579
  • 794