你需要檢查在「泛」事件中的X或Y位置,並返回false,如果它小於上「向下」 X或Y位置這樣
$('#your_reel_image').on('down', function(e, x, y, ev){
$(this).data("lastPosition",{"x":x,"y":y});//store the position on mousedown
}).on('pan', function(e,x,y,ev){//event when you do a mousemove while the mousedown
var $reel=$(this);
var delta=$reel.data("lastPosition").x-x;//difference between current and last position
if(delta<0){
$reel.data("lastPosition",{"x":x,"y":y});//update position
$reel.data("direction","right");//set current direction to right
}
else if(delta>0){
$reel.data("direction","left");//set current direction to left
return false;//prevent the reverse animation
}
});
我還添加了一個功能在fractionChange防止1幀反向動畫,如果你只,如果你想防止鼠標滾輪的反向動畫,你需要添加此功能
將光標移動到左側
$('#your_reel_image').on('fractionChange',function(){
if($(this).data("direction")=="left"){//if the current direction is left
$(this).data("direction","")//clear the current direction
return false;//return false prevent the 1 frame animation
//without the last line you can return 1 frame at a time on mouseup
}
});
會發生
$('#your_reel_image').on('wheel',function(e, distance, ev){
var $reel=$(this);
//almost the same as in the pan function without storing the position
if(distance<0){
$reel.data("direction","right");
}
else if(distance>0){
$reel.data("direction","left");
return false;
}
});
http://jsfiddle.net/N68qa/1/
你在說什麼? – sdespont
哈哈,我想這只是一個糟糕的問題,一般來說:-)我會嘗試重述。 – jckdnk111