2014-04-04 26 views
0

我正试图在jquery mobile中查找滑动的水平距离。在每个交换中,它仅返回其默认值(30)。 我已经通过以下方式尝试:

$('.ad-thumb-list').on("swipeleft swiperight",function(event){ 
    //alert("swipe"); 
     if(event.type == 'swipeleft'){ 
     // alert("left"); 

      alert($.event.special.swipe.horizontalDistanceThreshold); //i expect the different threshold values in different swipe.. 
      galleries[0].nextImage(); 
     } 
     else if(event.type == 'swiperight'){ 
      //alert("right"); 
      galleries[0].prevImage(); 
     } 
}); 

P.S我使用AD画廊插件。

+0

30px是用户为了触发滑动事件而应该通过的最小水平距离,所以它总是固定的。使用触摸事件来计算距离。 – Omar

+0

先生,请您详细说明一下吗?我尝试点击,敲打。我仍然没有得到结果。 – RamGrg

+0

我不确定是否有一个内置的方式让JQM显示你刷过多少像素,你可能需要一个替代方案--- http://labs.rampinteractive.co.uk/touchSwipe/demos/Swipe_status.html – Tasos

回答

0

通过设置自己的handleSwipe函数,您可以实际获得滑动距离(和时间),您可以在其中获取启动和停止对象。当你完成你所需要的任何事情后,你会决定触发一次滑动或不滑动。这只是挂钩到default handler code found here

$.event.special.swipe.handleSwipe = function(start, stop) { 
     $("#about-delta-x").html("delta-x: " + (stop.coords[0]-start.coords[0]).toString()); 
     if (stop.time - start.time < $.event.special.swipe.durationThreshold && 
      Math.abs(start.coords[ 0 ] - stop.coords[ 0 ]) > $.event.special.swipe.horizontalDistanceThreshold && 
      Math.abs(start.coords[ 1 ] - stop.coords[ 1 ]) < $.event.special.swipe.verticalDistanceThreshold) { 
      start.origin.trigger("swipe") 
       .trigger(start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight"); 
     } 
    };