-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedge-scroll-auto.min.js
1 lines (1 loc) · 2.49 KB
/
edge-scroll-auto.min.js
1
!function(i,e){this.radius=i,this.speed=e,this.scrolling=!1,this.proximity=null,this.clientX=null,this.clientY=null,this.scrollX=window.scrollX,this.scrollY=window.scrollY,this.innerWidth=window.innerWidth,this.innerHeight=window.innerHeight,this.handlers=[],this.deadzones=[],this.clampedVelocity=function(){var i=6,e=this.proximity/this.radius;return Math.pow(-1*e/2+1,i)},this.scrollTick=function(e){var n=this.lastTime?e-this.lastTime:0;if(this.lastTime=e,this.scrolling===!1)return this.lastTime=0;var t=0,s=0,l=this.innerWidth/2,o=this.innerHeight/2,r=this.clientX-l,h=this.clientY-o,d=Math.sqrt(Math.pow(r,2)+Math.pow(h,2)),c=r/d,a=h/d,u=c*this.speed*this.clampedVelocity(),w=a*this.speed*this.clampedVelocity();(this.clientX<=i||this.innerWidth-this.clientX<=i)&&(t=Math.round(u*n/1e3)),(this.clientY<=i||this.innerHeight-this.clientY<=i)&&(s=Math.round(w*n/1e3)),window.scrollBy(t,s),this.scrollX=window.scrollX,this.scrollY=window.scrollY,this.innerWidth=window.innerWidth,this.innerHeight=window.innerHeight,window.requestAnimationFrame(this.scrollTick)}.bind(this),this.scroll=function(i,e){window.scroll(i,e),this.scrollX=window.scrollX,this.scrollY=window.scrollY,this.innerWidth=window.innerWidth,this.innerHeight=window.innerHeight},this.onScroll=function(i){this.handlers.push(i)},this.offScroll=function(i){var e=this.handlers.indexOf(i);e>-1&&this.handlers.splice(e,1)};var n=this;document.addEventListener("mouseout",function(i){null===i.relatedTarget&&(n.scrolling=!1)}),document.addEventListener("mousemove",function(i){n.clientX=i.clientX,n.clientY=i.clientY;var e=i.clientX-0,t=n.innerWidth-i.clientX,s=i.clientY-0,l=n.innerHeight-i.clientY;if(n.proximity=Math.min(e,t,s,l),n.proximity<n.radius){if(n.dead)return;n.scrolling||(n.scrolling=!0,window.requestAnimationFrame(n.scrollTick))}else n.scrolling=!1}),document.addEventListener("scroll",function(){var i;i=n.scrolling?n:window;var e=i.scrollX,t=i.scrollY,s=i.innerWidth,l=i.innerHeight;n.handlers.forEach(function(i){i(e,t,s,l)})}),window.addEventListener("resize",function(){n.innerWidth=document.documentElement.clientWidth,n.innerHeight=document.documentElement.clientHeight}),this.addDeadzone=function(i){function e(){n.dead=!0,n.scrolling=!1}function t(){n.dead=!1}n.deadzones.push({elem:i,enter:e,leave:t}),i.addEventListener("mouseenter",e),i.addEventListener("mouseleave",t)},this.removeDeadzone=function(i){this.deadzones.forEach(function(e){e.elem===i&&(i.removeEventListener("mouseenter",e.enter),i.removeEventListener("mouseleave",e.leave))})}}(100,750);