2012-02-15 45 views
4

我與jQuery Mobile的應用程序,我在我的Android開發問題。jQuery Mobile的 - 改變taphold靈敏度

當我的意思是滾動項目列表時,即使在我觸摸的項目上也會觸發拉拍。

這對我的用戶來說非常令人沮喪。

我能做些什麼呢?

我可以改變taphold事件的靈敏度嗎?

很遺憾,我在Google上找不到任何東西。

感謝,

回答

7

在jQuery中移動1.1 *,他們已經增加了更多的方便的方式來配置觸摸事件:http://jquerymobile.com/demos/1.1.1/docs/api/events.html

對於taphold,您可以更改時間的自來水應該持續觸發前的量通過向$.event.special.tap.tapholdThreshold分配一個值時。

在導入JQM之前,但在導入jQuery之後,應在mobileinit事件中設置此值。舉例來說,我做了以下以避免刷卡和taphold事件之間沒有任何重疊:

<script type="text/javascript" src="/Scripts/jquery.min.js"></script> 
<!-- JQM default options must be set after jQuery and before jQuery-mobile --> 
<script type="text/javascript"> 
    $(document).bind("mobileinit", function() { 
     $.event.special.tap.tapholdThreshold = 1000, 
     $.event.special.swipe.durationThreshold = 999; 
    }); 
</script> 
<script type="text/javascript" src="/Scripts/jquery.mobile-1.1.0.js"></script> 
1

看到源:http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.js

查找水龍頭事件(開始於行1049):

$.event.special.tap = { 

在行1090至92年:

timer = setTimeout(function() { 
    triggerCustomEvent(thisObject, "taphold", $.Event("taphold")); 
}, 750); 

更改延遲taphold事件的觸發。

750ms = 0.75s 

1000 .....

1000 is equal to 1 second 

要評論

重新定義新的定時器設置的特別敲打事件:從750鏈接到1000

此代碼您可以將您的腳本包含AF後把jQuery Mobile的(<script src='jquery.mobile.js'></script>和TH EN <script>$.event.special.tap = {...}</script>

$.event.special.tap = { 
    setup: function() { 
     var thisObject = this, 
      $this = $(thisObject); 

     $this.bind("vmousedown", function(event) { 

      if (event.which && event.which !== 1) { 
       return false; 
      } 

      var origTarget = event.target, 
       origEvent = event.originalEvent, 
       timer; 

      function clearTapTimer() { 
       clearTimeout(timer); 
      } 

      function clearTapHandlers() { 
       clearTapTimer(); 

       $this.unbind("vclick", clickHandler) 
        .unbind("vmouseup", clearTapTimer) 
        .unbind("vmousecancel", clearTapHandlers); 
      } 

      function clickHandler(event) { 
       clearTapHandlers(); 

       // ONLY trigger a 'tap' event if the start target is 
       // the same as the stop target. 
       if (origTarget == event.target) { 
        triggerCustomEvent(thisObject, "tap", event); 
       } 
      } 

      $this.bind("vmousecancel", clearTapHandlers) 
       .bind("vmouseup", clearTapTimer) 
       .bind("vclick", clickHandler); 

      timer = setTimeout(function() { 
        triggerCustomEvent(thisObject, "taphold", $.Event("taphold")); 
      }, 1000); // Changed from 750 to 1000 
     }); 
    } 
}; 
+0

很好,謝謝。你認爲這可以在不破解核心的情況下完成嗎? – dan 2012-02-15 12:38:13

+1

我可以看到的唯一途徑是採取整個事件,並重新定義它。 – andlrc 2012-02-16 12:08:35