扩展 jQuery 的 .on() 以处理移动触摸事件
我正在尝试使用 jQuery mobile 事件,而不使用 jQuery mobile 的其余部分。
https://github.com/jvduf/jquery-mobile-events/ blob/master/jquery.mobile.events.js
该代码片段启用了所有这些功能,并且工作正常,但不适用于 .on() 事件处理程序。例如:
$('a').on('tap',function(){
console.log('Hi there!');
});
但是它确实可以与 .live() 一起使用,但现在已经被贬值了。
所以我的问题是;有没有办法扩展 .on() 功能以包括点击事件和其他事件?下面是完整列表:
- touchstart
- touchmove
- touchendorientationchange
- :)
- tap
- taphold
- swipe
- swipeleft
- swiperright
- scrollstart
- rollstop
谢谢
I am attempting to use the jQuery mobile events without the rest of jQuery mobile.
https://github.com/jvduf/jquery-mobile-events/blob/master/jquery.mobile.events.js
That snippet enables them all, and works fine, but not with the .on() event handler. E.g:
$('a').on('tap',function(){
console.log('Hi there!');
});
However it does work with .live(), but that is now depreciated.
So my question; is there a a way to extend the .on() functionality to include the tap event and others? Full list below:
- touchstart
- touchmove
- touchend
- orientationchange
- tap
- taphold
- swipe
- swipeleft
- swiperight
- scrollstart
- scrollstop
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,我认为您希望使用事件委托来保留替换元素上的这些事件。这意味着
需要将其更改为:
以便其行为与
$("a").live("tap", ...
So I take it that you want to use event delegation to preserve those events on replaced elements. That would mean that this:
would need to change to something like:
in order for it to behave the same as
$("a").live("tap", ...
也许为移动和桌面扩展 JQuery 事件代码应该更好。
一种方法是使用 JQuery vmouse(虚拟鼠标)插件。
来自 vmouse 插件评论:
有关更好的解释,请参阅 https://coderwall.com/p/ bdxjzg
vmouse 插件:https://github.com/jquery/jquery-mobile /blob/master/js/jquery.mobile.vmouse.js
另请参阅有关(触摸)事件当前状态的链接:http://blogs.adobe.com/ adobeandjquery/2011/03/07/the-current-state-of-touch-events/
Maybe it should be better to extend the JQuery event code for mobile and desktop.
One way to do this is to use the JQuery vmouse (virtual mouse) plugin.
From vmouse plugin comments:
For a better explanation, see https://coderwall.com/p/bdxjzg
vmouse plugin: https://github.com/jquery/jquery-mobile/blob/master/js/jquery.mobile.vmouse.js
Also see this link about current state of (touch) events: http://blogs.adobe.com/adobeandjquery/2011/03/07/the-current-state-of-touch-events/