2014-04-10 19 views
0

我已經內部文檔準備下面的代碼用來隱藏菜單點擊文件(背景)時。這工作正常。但是,如果用戶開始拖動,我需要取消隱藏 - touchstart。因此,如果用戶觸摸並「釋放」或取消觸摸,則隱藏菜單。但是,如果他們觸摸並開始拖動以查看更多菜單,菜單將保持可見。因爲它是現在,我嘗試取消如果touchmove啓動了touchend,但是這是行不通的。它仍然隱藏菜單。任何幫助在這裏將不勝感激。取消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(); 

    } 

}); 

回答

0

也許這可以幫助你

設置變量設置爲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; 
}); 
+0

感謝喬納森 - 我認爲這將永遠不會得到回答;) – Chris