/
slick-scroll.min.js
8 lines (8 loc) · 2.94 KB
/
slick-scroll.min.js
1
2
3
4
5
6
7
8
/*!
* slick-scroll
* A slick scroller for HTML elements or window (Valina javascript)
* @author Shy Alter
* @license MIT
* @version 0.0.8
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e["slick-scroll"]=t()}(this,function(){"use strict";var e={easeOutSine:function(e){return Math.sin(e*(Math.PI/2))},easeInOutSine:function(e){return-.5*(Math.cos(Math.PI*e)-1)},linear:function(e){return e},easeInQuad:function(e){return e*e},easeOutQuad:function(e){return e*(2-e)},easeInOutQuad:function(e){return e<.5?2*e*e:(4-2*e)*e-1},easeInCubic:function(e){return e*e*e},easeOutCubic:function(e){return--e*e*e+1},easeInOutCubic:function(e){return e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1},easeInQuart:function(e){return e*e*e*e},easeOutQuart:function(e){return 1- --e*e*e*e},easeInOutQuart:function(e){return e<.5?8*e*e*e*e:1-8*--e*e*e*e},easeInQuint:function(e){return e*e*e*e*e},easeOutQuint:function(e){return 1+--e*e*e*e*e},easeInOutQuint:function(e){return e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e}},t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}();return function(){function i(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t(this,i),this.element=e.element||window,this.speed=e.speed||500,this.easing=e.easing||"easeOutQuint",this.attempts=0,this.scrollTargetY=0,this.scrollY=this.element.scrollY}return n(i,[{key:"setSpeed",value:function(e){return this.speed=e,this}},{key:"setEasing",value:function(e){return this.easing=e,this}},{key:"to",value:function(e){return this.scrollTargetY=e instanceof Element?this.getNodeTop(e):e,this}},{key:"calcTime",value:function(){this.time=Math.max(.1,Math.min(Math.abs(this.scrollY-this.scrollTargetY)/this.speed,.8))}},{key:"getNodeTop",value:function(e){return e.offsetTop}},{key:"move",value:function(e){this.element===window?this.element.scrollTo(0,e):this.element.scrollTop=e}},{key:"calcScrollY",value:function(){this.scrollY=this.element===window?this.element.scrollY:this.element.scrollTop}},{key:"checkReady",value:function(){return this.element===window?"scrollTo"in this.element:"scrollTop"in this.element}},{key:"scroll",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){},i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};if(!(this.attempts>5)){if(!this.checkReady())return setTimeout(this.scroll(n,i),1+50*this.attempts),void(this.attempts=this.attempts+1);this.attempts=0,this.calcTime(),this.calcScrollY();var s=0;!function i(){var r=(s+=1/60)/t.time,u=e[t.easing](r);r<1?(requestAnimationFrame(i),t.move(t.scrollY+(t.scrollTargetY-t.scrollY)*u)):(t.move(t.scrollTargetY),n())}()}}}]),i}()});