Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript for iOS: Elastic Scrolling without disabling all Scrolling [duplicate]

I want to do two things:

  1. Disable Elastic Scrolling of document
  2. Enable scrolling of div.master

I know you can disable the elastic scrolling using the following:

document.addEventListener('touchmove',function(e) { e.preventDefault() },false);

However this disables all scrolling, not just the elastic scrolling. I thought maybe that you could just enable scrolling again for just the div.master but I'm not sure how you would do that.

I want just this section to scroll

like image 570
James Kyle Avatar asked Nov 20 '25 18:11

James Kyle


1 Answers

Disable your page’s default scrolling with:

document.body.ontouchmove = function(e) { e.preventDefault(); }; 

or

document.body.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);

and enable scrolling with some CSS:

.scrolling {
   overflow: auto;
   -webkit-overflow-scrolling: touch;
}

To completely remove elastic scrolling you’ll have to wrap the scrolling div inside another scrolling div like that:

<div class="scrolling">
  <div class="scrolling">
    // Your content goes here
  </div>
</div>
like image 154
Max Hoffmann Avatar answered Nov 23 '25 07:11

Max Hoffmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!