Detecting the sliding movement end gesture

// sliding direction detection 
var the startx, startY;
// get the angle
function getAngle (angx, Angy) {
return Math.atan2 (Angy, angx) * 180 [/ Math.PI;
};

// returns the start and end points according to an upward direction 2 left right 0 3 4 down No sliding
function for getDirection (the startx, startY, EndX, Endy) {
var = angx EndX - the startx;
var = Endy Angy - startY;
var Result = 0;

// if the slide distance is too short
if (the Math.abs (angx) <2 && the Math.abs (Angy) <2) {
return Result;
}

var angle = getAngle (angx, Angy);
IF (angle> = -135 && angle <= -45) {
Result . 1 =;
} the else IF (angle> 45 && angle <135) {
Result = 2;
} else if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135)) {
result = 3;
} else if (angle >= -45 && angle <= 45) {
result = 4;
}

return result;
}
//手指接触屏幕
document.addEventListener("touchstart", function(e) {
startx = e.touches[0].pageX;
starty = e.touches[0].pageY;
}, false);
//手指离开屏幕
document.addEventListener("touchend", function(e) {
var endx, endy;
endx = e.changedTouches[0].pageX;
endy = e.changedTouches[0].pageY;
var direction = getDirection(startx, starty, endx, endy);
if(self.show)
switch (direction) {
0 Case:
// Alert ( "not slide!");
BREAK;
Case. 1:
// Alert ( "Up!");
BREAK;
Case 2:
// Alert ( "Down!");
BREAK;
Case. 3:
// alert ( "left!");
BREAK;
Case. 4:
self.cutImg (-1);
BREAK;
default:
}
}, to false);

Guess you like

Origin www.cnblogs.com/sunww/p/11287504.html