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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With