滑動事件
阿新 • • 發佈:2017-06-05
math translate tar pow position posit log 向上 orm
var startPosition,endPosition,deltaX,deltaY,moveLength,; $(".cover").on(‘touchstart‘, function(e){ e.preventDefault(); var touch = e.touches[0]; startPosition = { x: touch.pageX, y: touch.pageY } }).on(‘touchmove‘, function(e){ e.preventDefault(); var touch = e.touches[0]; endPosition = { x: touch.pageX, y: touch.pageY }; deltaX = endPosition.x - startPosition.x; deltaY = endPosition.y - startPosition.y; //moveLength = Math.sqrt(Math.pow(Math.abs(deltaX), 2) + Math.pow(Math.abs(deltaY), 2)); }).on(‘touchend‘, function(e){ e.preventDefault(); if(deltaY < -50) { // 向上劃動 $(‘.wrap‘).css({ "-webkit-transform": "translate3d(0, -100%, 0)" }); startPosition=null; endPosition=null; deltaX=0; deltaY=0; } else if (deltaY > 0) { // 向下劃動 } });
滑動事件