2012-02-15 89 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