Home  >  Article  >  Web Front-end  >  Why Doesn\'t `window.onscroll` Work on iPhone/iPad?

Why Doesn\'t `window.onscroll` Work on iPhone/iPad?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-31 09:42:29393browse

 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn