-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswipe.min.js
1 lines (1 loc) · 1.69 KB
/
swipe.min.js
1
var swipe=function(b,c,d){var e=this;this.config={HTH:"object"==typeof d&&"undifine"!=typeof d.HTH&&"number"==typeof d.HTH?d.HTH:50,VTH:"object"==typeof d&&"undifine"!=typeof d.VTH&&"number"==typeof d.VTH?d.VTH:50,startX:0,startY:0,distanceX:0,distanceY:0,hasTouchMove:!1,direction:"none",touches:{touchstart:{x:-1,y:-1},touchmove:{x:-1,y:-1}},time:{allowedTime:500,elapsedTime:0,startTime:0},touchStartAt:{},touchEndAt:{}},this.touchFn=function(a){var f,d=e.config;if("undefined"!=typeof a&&"undefined"!=typeof a.touches)switch(a.preventDefault(),f=a.touches[0],a.type){case"touchstart":var g=a.changedTouches[0];d.distanceX=0,d.distanceY=0,d.startX=g.pageX,d.startY=g.pageY,d.touchStartAt=g,d.direction="none",d.hasTouchMove=!1,d.time.startTime=(new Date).getTime();case"touchmove":d.hasTouchMove=!0,d.touches[a.type].x=f.pageX,d.touches[a.type].y=f.pageY,c({direction:d.direction,touch:{startAt:d.touchStartAt,endAt:d.touchEndAt},touches:a.touches[0],type:a.type});break;case"touchend":var h=a.changedTouches[0];d.touchEndAt=h,d.distanceX=h.pageX-d.startX,d.distanceY=h.pageY-d.startY;var i=Math.abs(d.distanceX),j=Math.abs(d.distanceY);d.time.elapsedTime=(new Date).getTime()-d.time.startTime,d.time.elapsedTime<=d.time.allowedTime&&d.hasTouchMove&&(i>=j?i>=d.HTH&&(d.direction=d.touches.touchstart.x<d.touches.touchmove.x?"right":"left"):j>=d.VTH&&(d.direction=d.distanceY<0?"up":"down")),d.hasTouchMove=!1,c({direction:d.direction,touch:{startAt:d.touchStartAt,endAt:d.touchEndAt},touches:h,type:a.type})}},this.init=function(a){var a=document.querySelector(a);a.addEventListener("touchstart",this.touchFn,!1),a.addEventListener("touchmove",this.touchFn,!1),a.addEventListener("touchend",this.touchFn,!1)},this.init(b)};