1

Is there way to interrupt iOS scrolling using javascript?

Example 1: user is scrolling content by moving his finger through device screen. When some event happens user continue moving his finger without raising but there is no scrolling anymore.

Example 2: user initiated scrolling but stopped his finger without raising. Some event happens and scrollbar disappears.

Example 3: Momentum scrolling completely stops when some event happens.

User Created Image
  • 1,182
  • 2
  • 17
  • 33

2 Answers2

1

The first case could probably be covered using the following piece of code from another question

<script type="text/javascript">
   function blockMove() {
      event.preventDefault() ;
}
</script>

<body ontouchmove="blockMove()">

However, it will only work on iOS 8+. As for the other two cases I'm not aware of any method to do that.

Community
  • 1
  • 1
Rick
  • 3,240
  • 2
  • 29
  • 53
1

If you're talking about interrupting the iOS inertia/momentum scrolling, then I might have something for you.

First of all, you need to add fastclick.js. The lib removes the 300ms click delay on mobile devices and enables event capturing during inertia/momentum scrolling.

After including fastclick and attaching it to the body element, my code to interrupt scrolling looks like this:

scrollElement.style.overflow = 'hidden';
setTimeout(function() {
  scrollElement.style.overflow = '';
}, 10);

The trick is to set overflow: hidden, which stops the inertia/momentum scrolling. Please see my fiddle for a full implementation of stop scrolling during inertia/momentum.

Patrick Rudolph
  • 2,201
  • 17
  • 30