Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable inertial scrolling on body for iOS browsers?

I need to disable the inertial scrolling on the body element for iPad, but keep the ability to scroll the page without the inertia.

I have been looking for some time but I haven't found any good solutions. Maybe I am just not looking for the right thing? Is there any hack or workaround that could make this possible?

like image 628
Finglish Avatar asked Oct 07 '14 12:10

Finglish


2 Answers

You can use div with overflow property, it kill smooth iOS scroll

<body>
  <div class="scroll">
    long long text...
  <div>
</body>

Css

html,
body {
 height: 100%;
 margin: 0;
 overflow: hidden;
}
.scroll {
 overflow: auto;
 height: 100%;
}

http://jsbin.com/palixi/edit

like image 152
meuwka Avatar answered Oct 10 '22 02:10

meuwka


Add this to the body element's CSS:

-webkit-overflow-scrolling: auto;

The default for -webkit-overflow-scrolling is touch. That tells iOS devices to use "inertial" scrolling. The docs: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-overflow-scrolling

@meuwka answer achieves your goal, but in a roundabout way—it works because div elements have -webkit-overflow-scrolling: auto; as their default.

like image 24
Chris W. Avatar answered Oct 10 '22 02:10

Chris W.