-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeepDisTouchMove.min.js
1 lines (1 loc) · 1.06 KB
/
deepDisTouchMove.min.js
1
const disTouchMove=function(option){this.element=option.element?option.element:"body",this.direction=option.direction||"vertical",this.startX=this.startY=0,this._init(this.element,this.direction)};disTouchMove.prototype={_init:function(element){let _ele=document.querySelectorAll(element);_ele.length?_ele.length&&_ele.forEach(t=>{this._disTouchMove(t),t.childNodes.length&&this.dElement(t)}):console.log("element对象不存在")},dElement:function(element){element.childNodes.length?element.childNodes.forEach(t=>{t.childNodes.length&&this.dElement(t),this._disTouchMove(t)}):this._disTouchMove(element)},_disTouchMove:function(element){element.addEventListener("touchstart",e=>{let _touch=e.targetTouches[0];this.startX=_touch.pageX,this.startY=_touch.pageY}),element.addEventListener("touchmove",e=>{let _touch=e.targetTouches[0],diffX=Math.abs(_touch.pageX-this.startX),diffY=Math.abs(_touch.pageY-this.startY);diffX<diffY&&"vertical"==this.direction&&(e.stopPropagation(),e.preventDefault()),diffX>diffY&&"landscape"==this.direction&&(e.stopPropagation(),e.preventDefault())},!1)}};