TouchEvent.js:
function TouchEvent() {
this.tab = function (el) {
var startX, startY, endX, endY;
el.ontouchstart = function (e) {
e = e || window.event;
startX = e.changedTouches[0].clientX;
startY = e.changedTouches[0].clientY;
};
el.ontouchend = function (e) {
e = e || window.event;
endX = e.changedTouches[0].clientX;
endY = e.changedTouches[0].clientY;
if (Math.abs(startX - endX) < 10 || Math.abs(startY - endY) < 10) {
console.log("点击屏幕");
} else {
console.log("滑动屏幕");
if (startX > endX) {
console.log("向左滑动屏幕");
}
if (startX < endX) {
console.log("向右滑动屏幕");
}
if (startY > endY) {
console.log("向上滑动屏幕");
}
if (startY < endX) {
console.log("向下滑动屏幕");
}
}
};
};
}