0

I'm using a function to detect scrollTop and the do something. Its working on desktop browser but not on mobile devices:

$(window).scroll(function() {
    if ($(this).scrollTop() >= 80) {
      $('h2.main-info').addClass('scrolled');
    } else {
      $('h2.main-info').removeClass('scrolled');
    }
});

What would be the equivalent of scrollTop function for iPad?

codek
  • 343
  • 4
  • 20
  • 49
  • That should work just fine on mobile devices as well. I've tested to most smartphones but iPad though. What do you mean by its not working? – choz Jun 03 '16 at 07:16
  • @choz by not working I mean that after 80px of scroll on an iPad the class `scrolled` is not applied to `h2.main-info`. – codek Jun 03 '16 at 07:24
  • Can you try with `alert` and see if it's firing after `80px`? Or maybe try `$(window).scrollTop()` instead of `$(this).scrollTop()`, but I doubt it'd make any difference.. – choz Jun 03 '16 at 07:28
  • I've just tried it, the `alert` doesn't show. I'm testing it on Xcode, don't think that makes any difference :/ – codek Jun 03 '16 at 07:31
  • I dont have macs, I usually test on apple devices by using alerts :). Maybe this [thread](http://stackoverflow.com/questions/2863547/javascript-scroll-event-for-iphone-ipad) helps. You should also try whether that `scroll` event of yours is even firing at all.. – choz Jun 03 '16 at 07:34

0 Answers0