Tay*_*Mac 26 jquery jquery-selectors jquery-mobile
我已将jQuery实时点击事件替换为jQuery移动点击事件以提高响应速度.
我有一种感觉,出于兼容性原因这是一个坏主意.
是否有必要同时拥有这两个事件,有没有办法为同一个函数编写它们?
如('点击','点击')
J.T*_*age 34
比利的答案非常完整,实际上我使用它的次数很好.另外,您可能希望查看JQuery Mobile中的vmouse插件,它试图抽象鼠标事件:
// This plugin is an experiment for abstracting away the touch and mouse
// events so that developers don't have to worry about which method of input
// the device their document is loaded on supports.
Run Code Online (Sandbox Code Playgroud)
- https://github.com/jquery/jquery-mobile/blob/master/js/vmouse.js
我一直在玩我正在研究的项目,这些天似乎非常敏感.使用,如:
$('selector').bind('vclick', function () { ...
Run Code Online (Sandbox Code Playgroud)
要么
$('selector').bind('vmousedown', function () { ...
Run Code Online (Sandbox Code Playgroud)
Bil*_*oon 30
您可以在一个调用中绑定多个事件,如下所示:
$('selector').bind('click tap',function(){ ... })
Run Code Online (Sandbox Code Playgroud)
在某些浏览器/手机中这可能没什么问题,但是,这可能会使触发和点击的某些设备上的事件触发两次.
您可以通过执行某种设备/功能检测并添加适当的处理程序来解决此问题...
$('selector').bind( myCustomDetectionFunction() ? 'click' : 'tap' ,function(){ ... })
Run Code Online (Sandbox Code Playgroud)
此外,我认为touchstart并且mousedown是更好的选择事件.这是因为,在触摸之后,点击事件直到延迟已经过去才会触发,因为系统允许第二次触摸的机会使其成为双击或者成为轻扫手势等等.该touchstart事件立即触发一样,mousedown所以应该更敏感.
小智 10
我们开发了一个小脚本来解决这个问题.只需将其包含在全局级别中,您的点击事件将立即触发,而不会出现延迟事件的任何问题.
https://github.com/cargomedia/jquery.touchToClick