某些触摸事件会导致多个事件,我如何限制所需的事件?
因此,如果我点击或按住它,它会按预期工作,但如果我滑动,我应该得到两个事件。滑动和滑动方向,但我也得到了点击事件。如果发生滑动或滑动方向,有没有办法删除点击事件?
实例:
HTML:
<div data-role="page" id="home">
<div data-role="content">
<div id="display-event" class="add-border">
<p>Tap, TapHold (for 1 second), Swipe, SwipeRight or SwipeLeft</p>
</div>
</div>
</div>
JS:
function bindEvent(element) {
element.bind('tap taphold swipe swiperight swipeleft', function(event, ui) {
alert('Event: '+event.type);
});
}
bindEvent($('#display-event'));
更新: - http://jsfiddle.net/hJtAQ/31/(使用Jaspers方法)
So if I tap or taphold it works as expected, but if I swipe I should get two events. The swipe and the swipedirection, but I also get a tap event as well. is there a way to remove the tap event if swipe or swipedirection occurs?
Live Example:
HTML:
<div data-role="page" id="home">
<div data-role="content">
<div id="display-event" class="add-border">
<p>Tap, TapHold (for 1 second), Swipe, SwipeRight or SwipeLeft</p>
</div>
</div>
</div>
JS:
function bindEvent(element) {
element.bind('tap taphold swipe swiperight swipeleft', function(event, ui) {
alert('Event: '+event.type);
});
}
bindEvent($('#display-event'));
Related Question: Swipe event triggers tap event for ipod touch
Update:
- http://jsfiddle.net/hJtAQ/31/ (using Jaspers method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想验证触发的第一个事件,您可以为其余触发的事件设置超时和
preventDefault()
:If you want to only validate the first event that fires you can set a timeout and
preventDefault()
for the rest of the events fired: