javascript scroll event for iPhone/iPad?

后端 未结 5 1727
不知归路
不知归路 2020-11-22 15:38

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;

         


        
5条回答
  •  醉酒成梦
    2020-11-22 16:32

    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)

提交回复
热议问题