html5 手指触摸滑动事件代码(基于jquery)
$(document).ready(function(){
var startX,startY,endX,endY
var scrollTopVal=0; //左右滑动请自行修改
//假定接受手指触摸事件的Dom对象id是"touchBox"
document.getElementByIdx_x("touchBox").addEventListener("touchstart", touchStart, false);
document.getElementByIdx_x("touchBox").addEventListener("touchmove", touchMove, false);
document.getElementByIdx_x("touchBox").addEventListener("touchend", touchEnd, false);
//里面getElementByIdx_x 中 x_x 是新浪自己加的,用的时候请去掉
function touchStart(event){
var touch = event.touches[0];
startY = touch.pageY;
}
function touchMove(event){
var touch = event.touches[0];
endY = (startY-touch.pageY);
if(scrollTopVal==0){
$("#touchBox").scrollTop((endY+100));
}else{
$("#touchBox").scrollTop(scrollTopVal+endY+100);
}
}
function touchEnd(event){
scrollTopVal=$("#touchBox").scrollTop();
}
});