我正在尝试关闭侧边菜单 onclick
。然而,touchstart
也将滚动检测为点击,touchend
也是如此。
如何只检测 iPhone 上的点击(而不是滚动)?
$('#html').on("click touchstart",function(e) {
var optionsmenue = $(".adminmenu_label");
if(!optionsmenue.is(e.target) && optionsmenue.has(e.target).length === 0) {
document.getElementById("Optionsmenu").style.width = "0%";
document.getElementById("Optionsmenu").style.transition = "0.2s ease-out";
document.getElementById("adblue").style.display = "block";
document.getElementById("whatever").style.display = "block";
document.getElementById("not_related").style.display = "block";
document.getElementById("still_not_related").style.display = "block";
document.getElementById("still_still_not_related").style.width = "100%";
}
});
最佳答案
检测 iOS 并添加 cursor:pointer
对我有用,IOS 似乎有事件委托(delegate)问题。
var iOS = ["iPad","iPhone","iPod"].indexOf(navigator.userAgent) > -1;
if(iOS) {
$('body').css({ cursor : 'pointer' });
}
$('#html').on("click",function(e) {
// No need for touch start click will do the trick;
});
关于javascript - JS区分iPhone上的点击和滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48516800/