ios webkit中的touchend事件没有解雇? [英] touchend event in ios webkit not firing?
问题描述
我正在尝试为基于ios webkit的应用程序实现一个菜单,用户触摸/点击并按住菜单按钮('.menu_item'),在子菜单打开500ms后(div.slide_up_sub_menu)和用户应该能够将他们的手指/鼠标滑动到子菜单项并释放。
I'm trying to implement a menu for a ios webkit based app in which the user touches/clicks and holds a menu button ('.menu_item'), after 500ms the sub menu opens (div.slide_up_sub_menu), and a user should be able to slide their finger/mouse up to a submenu li item and release.
<li class="menu_item">
ASSET MANAGEMENT
<div class="slide_up_sub_menu hidden_menu">
<ul class="submenu">
<li>Unified Naming Convention</li>
<li>Version Control</li>
</ul>
</div>
</li>
应用程序应该能够检测到touchend / mouseup事件发生在哪个子菜单项上。我将touchstart事件绑定到菜单项,等待500ms,然后告诉子菜单显示。当用户释放他们的手指时,touchend事件应该触发关闭子菜单。如果用户已停止触摸子菜单项,则应检测到该子菜单项。目前检测到鼠标事件发生在哪个子菜单项在桌面上的Safari中工作:
The application should then be able to detect which submenu item the touchend/mouseup event happened on. I'm binding a touchstart event to the menu item, waiting for 500ms, and afterwards telling the submenu to show. When a user releases their finger a touchend event should fire closing the submenu. If the user has stopped their touch on a submenu item it should be detected. Currently detection of which submenu item a mouseup event happened on works in Safari on the desktop:
$('ul.submenu li').live('mouseup', function(e){
console.log($(e.currentTarget)); //works on the desktop
});
但是如果我使用touchend处理程序执行相同操作,它在ipad上不起作用:
but if I do the same using a touchend handler it doesn't work on an ipad:
$('ul.submenu li').live('touchend', function(e){
console.log($(e.currentTarget)); //never fires
});
如果我查找每个touchend事件,我可以在结束时获得对父子菜单项的引用触摸子菜单项:
if I look for every touchend event I can get a reference to the parent sub menu item when I end the touch on a submenu item:
$(document.body).bind('touchend', function(e) {
console.log($(e.target).html()); //logs ASSET MANAGEMENT
});
但没有对子菜单项的引用。
but no reference to the submenu item.
有没有人知道为什么没有在子菜单项上触发touchend事件?
Does anyone have any idea why a touchend event is not being fired on the submenu items?
谢谢
推荐答案
touchend因为touchcancel之前已经解雇而不会触发。如果你想要全触摸平均处理你需要打电话
touchend does not fire because touchcancel has fired earlier. If you want full touch evens handling you need to call
e.preventDefault()
,否则当浏览器确定这是一个滚动事件时会发生touchmove事件,它将触发touchcancel而从不消防联赛。
in the callback of "touchmove" event, otherwise when a touchmove event occurs if the browser decides that this is a scroll event it will fire touchcancel and never fire touchend.
这篇关于ios webkit中的touchend事件没有解雇?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!