我正在使用 jQuery 和 touchSwipe 插件来上下滚动内容。我遇到了一些与数学相关的问题,想看看社区是否可以快速帮助我解决这个问题。
touchSwipe“距离”变量仅返回从零开始的正值,因此当用户向上滑动然后决定向下滑动时,问题就出现了,因为距离值从 ex:(0 initial, 15up, 32up, 20up, 5 上、10 下、40 下)。我创建了 4 个 if 语句来捕捉所有这些情况。如何处理“方向变化”if 语句?
touchSwipe:http ://labs.skinkers.com/touchSwipe/
上下滑动功能:
var _scrolling=false;
var _prev=0;
$("#list").swipe({
swipeStatus:function(event, phase, direction, distance, fingerCount) {
if(phase=="end"){return false;}
if(phase=="move" && !_scrolling) {
var t = parseInt($("#list").css("top").split('px')[0]);
var s = 0;
if(direction=="up" && (distance-_prev) > 0){
//still moving up
s = t-(distance-_prev);
_prev=distance;
} else if(direction=="up" && (distance-_prev) < 0){
//direction change - moving down
} else if(direction=="down" && (distance-_prev) > 0){
//still moving down
s = t+(distance-_prev);
_prev=distance;
} else if(direction=="down" && (distance-_prev) < 0){
//direction change - moving up
}
_scrolling=true;
$("#list").animate({ top:s }, 70, function() {_scrolling=false;});
}<!--if end-->
}<!--swipeStatus end-->
});