使用Javascript模拟滚动事件 [英] Simulate scroll event using Javascript

查看:787
本文介绍了使用Javascript模拟滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Javascript for Mobile Safari模拟滚动事件。
我使用以下代码

I am trying to Simulate a scroll event using Javascript for Mobile Safari. I am using the following code

var evt = document.createEvent("MouseEvents");    
evt.initMouseEvent("scroll", true, true, window,0, 0, 0, 0, 0, false, false, false, false, 0, null);

以上代码是jQuery插件jQuery.UI.Ipad的一部分,它基本上映射触摸事件,如touchstart ,touchmove,touchend鼠标事件,如mouseover,mousedown等

The above code is part of a jQuery plugin jQuery.UI.Ipad which basically maps touch events like touchstart,touchmove,touchend to mouse events like mouseover, mousedown,etc

由于某些原因,模拟滚动事件的代码无法正常工作......请帮助我。所以基本上我的问题是如何模拟滚动事件。
谢谢。

Howevert for some reasons the code for simulating a scroll event is not working...Please help me. So essentially my question is how do I simulate the scroll event. Thank you.

推荐答案

我认为人们对为什么要覆盖滚动控件感到困惑。我可以看到为什么你想模仿鼠标事件,但滚动可能不应该是其中之一。

I think people are confused as to why you would overide the scroll control. I can see why you want to imitate mouse events, but scroll maybe should not be one of them.

通常对于滚动更改你可以得到滚动:

Usually for scroll changes you can just get the scroll with:

var top = document.body.scrollTop;

并设置为:

document.body.scrollLeft = sX;
document.body.scrollTop = sY;

这篇关于使用Javascript模拟滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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