2011-08-04 49 views

回答

1

你需要採取的腳本相隔位,獲得您需要的功能。基本上你有什麼有保存「刷卡」,以一個單一的事件,您需要捕獲的TouchMove事件是這樣的:

//add to the decleration: 
var defaults = { 
    threshold: { 
     x: 30, 
     y: 10 
    }, 
    swipeLeft: function() { alert('swiped left') }, 
    swipeRight: function() { alert('swiped right') }, 
    //THIS: 
    swipeMove: function(distance) { alert('swiped moved: '+distance.x+' horizontally and '+distance.y+' vertically') }, 
    preventDefaultEvents: true 
}; 

//add this to the init vars section 
var lastpoint = {x:0, y:0} 

//add an init to the lastpoint at start of swipe 
function touchStart(event) { 
     console.log('Starting swipe gesture...') 
     originalCoord.x = lastpoint.x = event.targetTouches[0].pageX 
     originalCoord.y = lastpoint.y = event.targetTouches[0].pageY 
    } 

//this is where you do your calculation 
function touchMove(event) { 
     if (defaults.preventDefaultEvents) 
      event.preventDefault(); 

     var difference = { 
      x:event.targetTouches[0].pageX - lastpoint.x, 
      y:event.targetTouches[0].pageY - lastpoint.y 
     } 
     //call the function 
     defaults.swipeMove(difference); 

     finalCoord.x = lastpoint.x = event.targetTouches[0].pageX 
     finalCoord.y = lastpoint.y = event.targetTouches[0].pageY 
    } 

應該是類似的東西反正havnt測試它雖然。

+0

我可以證實這是行不通的 – Xavier

+0

您需要對您所引用的代碼進行上述修改,但這不是完整的代碼。你需要做一些工作;) – longstaff

+0

我確實根據你在代碼中註釋的位置進行了修改... – Xavier