2016-07-10 125 views
0

我最近開始使用一個很棒的插件來將觸摸轉換爲鼠標點擊。不過,就在今天我遇到一個問題觸摸衝 - 轉換點擊觸摸

jQuery('.draggable').click(function(){ 
    alert('clicked'); 
}) 

來到火災警報,我需要做兩個觸摸(移動設備),而電腦上我只需要一個鼠標點擊。可能是什麼問題?謝謝。

回答

0
// set a var as false as a way to change and flag if something is being dragged 

var dragCheck = false; 
$('.element').draggable({ 
     revert: true, 
    drag: function(){ 
      // On drag set that flag to true 
     dragCheck = true; 
    }, 
    stop: function(){ 
      // On stop of dragging reset the flag back to false 
     dragCheck = false; 
    } 
}); 

// Then instead of using click use mouseup, and on mouseup only fire if the flag is set to false 

$('.element') .bind('mouseup', function(){ 
     if(dragCheck == false){ 
      // do the click action here... 
     } 
});