浏览器中的jQuery touchstart [英] jquery touchstart in browser
问题描述
由于大多数桌面浏览器尚不支持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屋!