jquery touchstart在浏览器中

由于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事件必须传播到文档,才能触发自定义touchstart事件。这可能会有意想不到的副作用。

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...