JQ判斷頁面上下滑動進入上、下頁

// 判斷滑動進入上、下頁
function goNext($ele,callback){
	var startY , endY , diff;
	$ele.on('touchstart',touchStart);
	$ele.on('touchmove',touchMove);
	$ele.on('touchend',touchEnd);
	function touchStart(e){
		diff = 0;
		var touch = e.originalEvent.targetTouches[0];
		startY = touch.pageY;
	}
	function touchMove(e){
		e.preventDefault();
		var touch = e.originalEvent.targetTouches[0];
		endY = touch.pageY;
		diff = endY - startY;
	}
	function touchEnd(e){
		if(Math.abs(diff) > 150){
			if(diff< 0){
				callback && callback(1);
			}else{
				callback && callback(2);
			}
		}
	}
}

// 引用
 goNext($('.pageone'),(type) => {
     type == 1 ? '向上' : '向下';
 });


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章