我使用以下代码在单击表单外部时隐藏 div 和覆盖 div。
下面的javascript是:
$(document).mouseup(function (e)
{
var container = $("#feedbackform");
var overlay = $("#overlay");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
$('#feedbackform').fadeOut('fast'),
$('#overlay').fadeOut('fast');
}
});
这在台式机上运行良好,但在触摸移动设备上运行不佳。
我猜它与 mouseup 有关,有什么建议吗?
克雷格。
最佳答案
经典事件在移动设备上的工作方式并不完全相同(除了一些事件,例如“点击”,这是完全相同的)。
现在您有一些名为touch events
的特定于移动设备的事件:https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Touch_events
所以 touchend 可能是你想要使用的那个:
$(document).on('mouseup touchend', function (e){
[...]
});
关于javascript - 鼠标向上 - 在 Div 之外单击在移动设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24356366/