JQuery Mobile – 改变taphold灵敏度

我在Android上开发的JQuery移动应用程序有问题。

通常,当我只想滚动一个项目列表时,即使在我触摸的项目上也会触发。

这对我的用户来说非常令人沮丧。

我该怎么办?

我可以改变taphold事件的灵敏度吗?

很遗憾,我在谷歌上找不到任何东西。

谢谢,

在jQuery-mobile 1.1。*中,他们添加了更方便的方法来配置触摸事件: http : //jquerymobile.com/demos/1.1.1/docs/api/events.html

对于taphold,您可以通过为$.event.special.tap.tapholdThreshold分配值来$.event.special.tap.tapholdThreshold触发事件之前应该持续的时间量。

在导入JQM之前,但在导入jQuery之后,应在mobileinit事件中设置此值。 例如,我做了以下操作以避免滑动和taphold事件之间的任何重叠:

     

请参阅源代码: http : //code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.js

查找点击事件(从第1049行开始):

 $.event.special.tap = { 

在1090到1092行:

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

更改taphold事件触发的延迟。

 750ms = 0.75s 

1000是…..

 1000 is equal to 1 second 

评论

使用新的计时器设置重新定义特殊点击事件:链接从7501000

你的脚本包含在jQuery mobile( 然后

 $.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 }); } };