【问题标题】:Touch punch - convert clicks to touches触摸打孔 - 将点击转换为触摸
【发布时间】:2016-07-10 14:16:15
【问题描述】:

我最近开始使用一个很棒的插件来将触摸事件转换为鼠标点击。但是就在今天我遇到了一个问题

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

要触发警报,我需要进行两次触摸(移动设备),而在计算机上我只需单击一次鼠标。可能是什么问题?谢谢。

【问题讨论】:

    标签: jquery-ui jquery-ui-touch-punch


    【解决方案1】:
    // 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...
          }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-07
      • 2023-03-27
      • 1970-01-01
      相关资源
      最近更新 更多