适用于iPhone / iPad的javascript滚动活动? [英] javascript scroll event for iPhone/iPad?

查看:215
本文介绍了适用于iPhone / iPad的javascript滚动活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在iPad上捕捉滚动事件。
这些都不起作用,我做错了什么?

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;

window.attachEvent("scroll",myFunction,false);

document.attachEvent("scroll",myFunction,false);

它们甚至可以在Windows上的Safari 3上运行。
具有讽刺意味的是,PC上的每个浏览器都支持 window.onload = 如果您不介意破坏现有事件。但不能继续使用iPad。

They all work even on Safari 3 on Windows. Ironically, EVERY browser on the PC supports window.onload= if you don't mind clobbering existing events. But no go on iPad.

推荐答案

iPhoneOS会捕获 onscroll 事件,除了你没想到的方式。

The iPhoneOS does capture onscroll events, except not the way you may expect.


单手平移不会产生任何事件,直到用户停止平移 - 一个 onscroll 当页面停止移动并重绘时会生成事件 - 如图6-1所示。

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.

同样,只有在你停止滚动后,用2个手指滚动 onscroll

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 

(另请参阅 https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariWebContent/ HandlingEvents / HandlingEvents.html

这篇关于适用于iPhone / iPad的javascript滚动活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆