在YUI的旧版本中,无法模拟touchevent(touchstart / touchmove / touchend),我们可以在官方yui网站上阅读:http://yuilibrary.com/yui/docs/event/simulate.html(无触摸事件部分)
但是在最后一个版本的YUI(3.6.0)中,似乎可以模拟touchevent。当您查看此文件:http://yuilibrary.com/yui/docs/api/files/event-simulate_js_event-simulate.js.html#l60时,会在脚本中实现touchevents。
如果你看一下这篇文章:http://www.yuiblog.com/blog/2012/08/10/twiy/; YUI接受关于手势模拟的拉取请求。
但是当我这样做时:
Y.one('mydiv').simulate('touchstart');
我有这样的信息:
Error: simulate(): Event 'touchstart' can't be simulated. Use gesture-simulate module instead.
所以我尝试使用“gesturemovestart”并执行
Y.one('mydiv').simulate('gesturemovestart');
但我有这样的信息:
Event 'gesturemovestart' can't be simulated
所以,有人知道是否有可能在YUI上模拟touchevent,如果是,为什么我会有这个错误?
答案 0 :(得分:2)
如果你在git hub上引用yui3中的event-simulate.js https://github.com/yui/yui3/blob/master/build/event-simulate/event-simulate.js,评论的第725行说touchevents期望param touchList [表示与此事件相关的所有触摸的Touch对象的集合]。 所以,如果你尝试类似的东西 Y.one(“#myDiv”)。模拟(“touchstart”,{touches:{PageX:200,PageY:200}});
它应该模拟touchstart事件。
由于触摸和手势事件在iOS(2.0及更高版本)上可用,测试应该在ios设备上成功通过。
答案 1 :(得分:0)
我终于找到了答案。
你可以做Y.one("#myDiv")。模拟(" touchstart",{touches:{PageX:0,PageY:0}});但仅适用于Android& iOs系统,适用于我的脚本(在平板电脑和智能手机上运行)。
您必须更新到YUI 3.6.0。 ,如果你想使用它。
如果你参考这篇文章:http://yuilibrary.com/forum/viewtopic.php?f=18&t=10521,手势模拟将在YUI下一版本3.6.1中实现。