Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript scroll event for iPhone/iPad?

I can't seem to capture the scroll event on an iPad. None of these work, what I am doing wrong?

window.onscroll=myFunction;  document.onscroll=myFunction;  window.attachEvent("scroll",myFunction,false);  document.attachEvent("scroll",myFunction,false); 

They all work even on Safari 3 on Windows. Ironically, EVERY browser on the PC supports window.onload= if you don't mind clobbering existing events. But no go on iPad.

like image 560
ck_ Avatar asked May 19 '10 07:05

ck_


People also ask

Does scroll event work on mobile?

jQuery Mobile provides two scroll events: when scrolling starts and when scrolling stops.

Does scroll event bubble?

The scroll event does not bubble up. Although the event does not bubble, browsers fire a scroll event on both document and window when the user scrolls the entire page.


1 Answers

The iPhoneOS does capture onscroll events, except not the way you may expect.

One-finger panning doesn’t generate any events until the user stops panning—an onscroll event is generated when the page stops moving and redraws—as shown in Figure 6-1.

Similarly, scroll with 2 fingers fires onscroll only after you've stopped scrolling.

The usual way of installing the handler works e.g.

window.addEventListener('scroll', function() { alert("Scrolled"); }); // or $(window).scroll(function() { alert("Scrolled"); }); // or window.onscroll = function() { alert("Scrolled"); }; // etc  

(See also https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html)

like image 129
kennytm Avatar answered Sep 18 '22 17:09

kennytm