由于大多数桌面浏览器尚不支持touchstart / touchend。如何创建与mousedown事件相同的touchstart事件(所有浏览器都支持)。
我想要这样的东西
$('obj').bind('touchstart', function(e){
});
将被翻译成
$('obj').bind('mousedown', function(e){
})
最佳答案
您可以一次绑定两个...
$('obj').bind('touchstart mousedown', function(e){
});
如果要使
mousedown
事件自动触发touchstart
事件(因此只需要绑定touchstart
),请使用...$(document).bind('mousedown', function(event) {
$(event.target).trigger('touchstart');
});
请注意,这意味着
mousedown
事件必须先传播到document
,然后才能触发自定义touchstart
事件。这可能会产生意想不到的副作用。关于jquery - 浏览器中的jQuery touchstart,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9389968/