浏览器中的jQuery touchstart [英] jquery touchstart in browser

查看:97
本文介绍了浏览器中的jQuery touchstart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于大多数桌面浏览器尚不支持touchstart/touchend.如何创建与mousedown事件相同的touchstart事件(所有浏览器都支持).

As touchstart/touchend is yet not supported in most of the desktop browsers. How can I create touchstart event that will be the same as mousedown event (that is supported in all browsers).

我想要这样的东西

$('obj').bind('touchstart', function(e){
});

将被翻译成

$('obj').bind('mousedown', function(e){
})

推荐答案

您可以一次绑定两者...

You can bind both at once...

$('obj').bind('touchstart mousedown', function(e){
});

如果要mousedown事件自动触发touchstart事件(因此您只需绑定touchstart),请使用...

If you want to mousedown event to fire touchstart events automatically (so you only need to bind touchstart) use...

$(document).bind('mousedown', function(event) {
    $(event.target).trigger('touchstart');
});

请注意,这意味着mousedown事件必须传播到document,然后才能触发自定义touchstart事件.这可能会带来意想不到的副作用.

Note that this means mousedown events must propagate to document before the custom touchstart event can be triggered. This could have unexpected side effects.

这篇关于浏览器中的jQuery touchstart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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