Home > Web Front-end > JS Tutorial > body text

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

Patricia Arquette
Release: 2024-10-31 09:42:29
Original
401 people have browsed it

 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"); });
Copy after login

or equivalent jQuery syntax:

$(window).scroll(function() { alert("Scrolled"); });
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!