Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

onscroll event not being triggered on iPad after single touch panning?

In trying to figure out the scroll position for a UIWebView, I'm attaching a listener in the HTML that will call back to the main app. I attach the javascript listener like:

window.onscroll = function reportScroll() {
    var sY = window.pageYOffset;
    alert('Scroll pos: '+sY);  // Would evetually trigger a URL or something
}

This event only seems to be triggered at the end of a flick scroll on OS 3.2 (iPad), once the deceleration has ended. However this: https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW7 seems to indicate that it should be triggered at the end of a single finger pan as well. I really need to know when that pan completes as well.

like image 276
Matt Hall Avatar asked Jul 09 '10 21:07

Matt Hall


2 Answers

According to QuirksMode Safari iPhone doesn't fire onscroll event on window, but rather on the document (and any other element). I would bet Safari iPad does the same thing.

like image 194
25 revs, 4 users 83% Avatar answered Nov 10 '22 05:11

25 revs, 4 users 83%


I experienced the same problem in iPhone as well: flick scroll correctly produces the onscroll event, but single finger panning does not (I was using this in my fixed menu implementation, where the menu is hidden after ontouchstart event, and restored after onscroll).

I solved the problem by using two parallel events: onscroll and ontouchend. They both refer now to the same event handler (that restores the menu). As events are suppressed during scroll, the ontouchend event does not get fired if the window continues the flick scrolling. Now the event handling works for both flick scroll and panning.

I have not tested this in iPad, I would be interested in knowing if this fix helps in that as well.

like image 27
Sami Avatar answered Nov 10 '22 05:11

Sami