13

I'm trying to get the scrollTop() value while scrolling a website on the iPad/iPhone.

$(window).scroll(function(){
    console.log($(window).scrollTop());
});

I'm using this code for normal desktop browsers. On Safari with the Mac the console shows every pixel while scrolling. But on the iPad, I only get the value when the scrolling stops.

How can I get every scrollTop value while scrolling even on the iPad?

Puroto
  • 153
  • 1
  • 3
  • 16
Slevin
  • 4,268
  • 12
  • 40
  • 90
  • Have a look here: http://stackoverflow.com/q/2863547/1414562 – A. Wolff May 16 '13 at 17:25
  • Unfortunately that does not work either because it does not return the pixels while the bounce/rubberband/anything effect, that iOS scrolling provides – Slevin May 16 '13 at 18:00
  • You have to use the gesturechange event to, it seems to give this exact behaviour. I outline it on this question http://stackoverflow.com/questions/2863547/javascript-scroll-event-for-iphone-ipad/17195346#17195346 – Dave Mackintosh Jun 20 '13 at 13:27

4 Answers4

1

This limitation changed in iOS 8

This continues to log $(window).scrollTop() after touchend while the inertia/bounce effect is running:

$(document).on( 'scroll', function(){
console.log($(window).scrollTop());});

tested on iPad 9.2, iPhone 9.3.4

Claytronicon
  • 1,437
  • 13
  • 14
1

Have you tried the following?

$(document).on( 'scroll', function(){
  var currentPosition = $(window).scrollTop();
  console.log(currentPosition);
});
iPzard
  • 2,018
  • 2
  • 14
  • 24
0

Do not make overflow hidden or scrollTop wont work on safari. Just make overflow: auto;

html,body {
  overflow-x: auto;
  overflow-y: auto;
}
Sourav Purkait
  • 248
  • 2
  • 6
-3

Try using window.pageYOffset and window.pageXOffset.