-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrog.min.js
2 lines (2 loc) · 1.37 KB
/
Drog.min.js
1
2
/*! Drog.js v1.2.1 | (c) 2021, Emanuel Rojas Vásquez | BSD 3-Clause License */
!function(e,t){if(e.Drog)return console.error("Drog.js has already been defined");let n="-Xi",o="-Yi",c="-Xf",i="-Yf",r="-x",s="-y",l="mousedown",u="touchstart",a="mousemove",f="touchmove",h="mouseup",d="touchend",y="-f",m={passive:!1},p="-d",g="[data-drog]",v,x;function X(e,t,n,o){e.addEventListener(t,n,o||!1)}function Y(e,t,n,o){e.removeEventListener(t,n,o||!1)}function w(e){2!==e.which&&3!==e.which&&(x=this,v=x[y],v[n]=e.clientX||e.targetTouches[0].clientX,v[o]=e.clientY||e.targetTouches[0].clientY,e.type===u?(X(x,f,D,m),X(x,d,T,m)):(X(t,a,D),X(t,h,T)))}function D(e){e.preventDefault(),e.type===f&&(v=this[y]),v[c]=e.clientX||e.targetTouches[0].clientX,v[i]=e.clientY||e.targetTouches[0].clientY,v[r]-=v[n]-v[c],v[s]-=v[o]-v[i],v[n]=v[c],v[o]=v[i],v.style.transform="translate("+v[r]+"px,"+v[s]+"px)"}function T(){x=this,Y(t,a,D),Y(t,h,T),Y(x,f,D,m),Y(x,d,T,m)}e.Drog={on:function(t){if(!t[p]){let e=t.querySelector(g)||t;(e[y]=t)[r]=0,t[s]=0,t.style.zIndex=10,e.style.touchAction="none",t[p]=!0,X(e,l,w),X(e,u,w,m)}},off:function(t){if(t[p]){let e=t.querySelector(g)||t;t.style.zIndex="",t.style.transform="",e.style.touchAction="",e[y]=t[p]=null,Y(e,l,w),Y(e,u,w)}},move:function(e,t,n){e[p]&&(t=parseFloat(t)||0,n=parseFloat(n)||0,e[r]=t,e[s]=n,e.style.transform="translate("+t+"px,"+n+"px)")}}}(window,document);