模拟touchstart和touchend事件? [英] Simulating touchstart and touchend events?

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

问题描述

我正在开发一个主要用于ipad的jquery组件.因此,无论如何都可以在桌面上模拟"touchstart"和"touchend"事件,而不是让设备本身来检查事件.

I'm developing a jquery component which works primarily for ipad. So is there anyway to simulate 'touchstart and 'touchend' events in desktop rather than having the device itself to check the events.

推荐答案

您可以在jQuery中编写自己的自定义事件:

You can author your own custom events within jQuery:

var event = $.Event( "touchstart", { pageX:200, pageY:200 } );

您可以针对DOM中的任何元素发布它们:

And you can issue them against any element in the DOM:

$("body").trigger( event );

演示: http://jsbin.com/ezoxed/edit#javascript,html
进一步阅读: http://api.jquery.com/category/events/event-object /

Demo: http://jsbin.com/ezoxed/edit#javascript,html
Further reading: http://api.jquery.com/category/events/event-object/

请记住,现在市场上还有各种其他类型的接口不支持touchstarttouchend事件.例如,Windows 8已经在移动市场上占领了平板电脑,它使用了一个更加抽象的由Pointers组成的事件模型.

Keep in mind that there are various other types of interfaces on the market now that don't support touchstart and touchend events. For instance, Windows 8 is already occupying tablets in the mobile market, and it uses a more abstracted event model consisting of Pointers.

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

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