Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如果用户触摸拖动,则取消触摸结束_Jquery_Touch_Drag - Fatal编程技术网

Jquery 如果用户触摸拖动,则取消触摸结束

Jquery 如果用户触摸拖动,则取消触摸结束,jquery,touch,drag,Jquery,Touch,Drag,我在docready中有以下代码,用于在单击文档(后台)时隐藏菜单。这个很好用。但是,如果用户启动拖动-touchstart,我需要取消隐藏。因此,如果用户触摸并“释放”或取消触摸,菜单将隐藏。但是如果他们触摸然后开始拖动以查看更多菜单,菜单将保持可见。现在,如果启动了touchmove,我会尝试取消touchend,但这不起作用。它仍然隐藏菜单。这里的任何帮助都将不胜感激 var touchmove = false; $(document).on('touchmove',function()

我在docready中有以下代码,用于在单击文档(后台)时隐藏菜单。这个很好用。但是,如果用户启动拖动-
touchstart
,我需要取消隐藏。因此,如果用户触摸并“释放”或取消触摸,菜单将隐藏。但是如果他们触摸然后开始拖动以查看更多菜单,菜单将保持可见。现在,如果启动了
touchmove
,我会尝试取消
touchend
,但这不起作用。它仍然隐藏菜单。这里的任何帮助都将不胜感激

var touchmove = false;
$(document).on('touchmove',function() {
    touchmove = true;
})

var click_or_touch = is_touch_divice ? 'touchend' : 'click'

$(this).on(click_or_touch, function() {

    if (touchmove == true) return false;

    if ($('.popup_item').is(':visible')) {

        $('.popup_item').hide();

    }

});

也许这可以帮助你

将变量设置为false

var isDrag = false;
将var设置为true ontouchmove

$("body").on("touchmove", function(){
  isDrag = true;
});
你的钮扣

$("#button").on("touchend", function(){
      if (isDrag)
      return;

      // Your button actions here; do your magic
});
重置变量

$("body").on("touchstart", function(){
    isDrag = false;
});

谢谢乔纳森-我以为这永远不会得到回答;)