"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Doesn\'t `window.onscroll` Work on iPhone/iPad?

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

Published on 2024-11-08
Browse:311

 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

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3