JS区分iPhone上的点击和滚动

时间:2018-01-30 08:16:18

标签: javascript jquery ios

我试图关闭Sidemenu 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%"; 
      }
    });

2 个答案:

答案 0 :(得分:2)

检测iOS并添加cursor:pointer对我有用,IOS似乎在事件委派方面存在问题。

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;
});

答案 1 :(得分:0)

应删除

中的“touchstart”
$('#html').on("click touchstart",function(e) {