11

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?

Chris W.
  • 37,583
  • 36
  • 99
  • 136
Finglish
  • 9,692
  • 14
  • 70
  • 114
  • 2
    take a look here: https://gist.github.com/amolk/1599412 – Monte Oct 07 '14 at 12:43
  • Basically you will have to block the user from swiping the screen via javascript that "removes" the touchmove event. Check Monte's comment for a link. – Alex Oct 07 '14 at 12:55
  • @Monte Thanks for responding, I have updated my question to make it clearer, as I still want to be able to scroll the body, I just need to to scroll without inertia. – Finglish Oct 07 '14 at 13:13

5 Answers5

21

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.

Chris W.
  • 37,583
  • 36
  • 99
  • 136
  • 2
    This work, but at a price. You lose the smooth scrolling. – user3106759 Jun 27 '16 at 09:07
  • This should be the accepted answer, while meuwka answer works. It is only because the -webkit-overflow-scrolling defaults differently for elements that are not the body. – Vargr Aug 27 '18 at 12:16
  • `webkit-overflow-scrolling` is a non-standard feature: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-overflow-scrolling – tgordon18 Sep 28 '18 at 17:17
  • @tgordon18 well if we're specifically targeting iOS browsers I don't think that really matters – andrewtweber Mar 20 '19 at 21:32
  • 2
    I've tried this alone and in combination with `overflow: hidden` but I don't think this is working on iOS anymore. Tried to visualise it here: https://codepen.io/calsal/full/Exxjwwo. Scroll is disabled on desktop. On iOS Safari (by first scrolling down a bit and then up) I still get the inertia effect. Please advise if i'm wrong. – Calsal Oct 09 '19 at 10:31
5

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

meuwka
  • 139
  • 8
0

I've used inobounce which can be found here

You'll notice you have to specify a height property and overflow: auto to the element you'd like scrollable, including -webkit-overflow-scrolling: touch;. The docs do a good job at explaining.

Mike
  • 1,884
  • 2
  • 24
  • 42
0

Just setting the -webkit-overflow-scrolling rule to html and body doesn't work for me.

I had to set webView.scrollView.bounces = false in the viewDidLoad func in swift.Try it and let us know if it solves your problem.

Nick
  • 3,454
  • 6
  • 33
  • 56
Simon
  • 17
  • 3
0

iOS13 changes :

Accelerated Scrolling on iOS and iPadOS

Accelerated scrolling the main frame has always been available with WebKit on iOS. In addition, developers could use a CSS property called -webkit-overflow-scrolling to opt-in to fast scrolling for overflow scroll. None of that is necessary with iPadOS and iOS 13. Subframes are no longer extended to the size of their contents and are now scrollable, and overflow: scroll; and iframe always get accelerated scrolling. Fast scrolling emulation libraries are no longer needed and -webkit-overflow-scrolling: touch; is a no-op on iPad. On iPhone, it still has the side-effect of creating a CSS stacking context on scrollable elements. Developers will want to test their content to see how hardware accelerated scrolling everywhere affects it and remove unnecessary workarounds.

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689