iPhone/iPad 的 javascript 滚动事件? [英] javascript scroll event for iPhone/iPad?

查看:35
本文介绍了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天全站免登陆