由于大多数桌面浏览器尚不支持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/

10-09 12:48