Home > Article > Web Front-end > Why Doesn\'t `window.onscroll` Work on iPhone/iPad?
Event Capturing on iPhone/iPad with Scroll Event
While attempting to capture the scroll event on an iPad, troubleshooting efforts reveal that common approaches such as window.onscroll and document.onscroll fail to trigger the desired response.
Understanding Event Handling on iOS Devices
The iPhoneOS event handling mechanism differs from traditional desktop browsers. It doesn't generate scroll events during continuous one-finger panning or two-finger scrolling. Instead, events are triggered when the user stops moving the page and it redraws.
Capturing Scroll Events on iPhone/iPad
To capture scroll events successfully on iPhone/iPad, use event listeners such as:
window.addEventListener('scroll', function() { alert("Scrolled"); });
or equivalent jQuery syntax:
$(window).scroll(function() { alert("Scrolled"); });
Additional Resources
For further reference, consult Apple's documentation on handling events in Safari web content: https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html
The above is the detailed content of Why Doesn\'t `window.onscroll` Work on iPhone/iPad?. For more information, please follow other related articles on the PHP Chinese website!