sweet-scroll
Advanced tools
Comparing version 0.6.2 to 0.7.0
{ | ||
"name": "sweet-scroll", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"description": "Modern and the sweet smooth scroll library.", | ||
@@ -5,0 +5,0 @@ "main": "sweet-scroll.js", |
@@ -99,3 +99,4 @@ sweet-scroll.js | ||
cancelScroll: null, | ||
completeScroll: null | ||
completeScroll: null, | ||
stepScroll: null, | ||
} | ||
@@ -259,2 +260,3 @@ ``` | ||
- `completeScroll: function(isCancel){}` | ||
- `stepScroll: function(currentTime, props){}` | ||
@@ -440,2 +442,7 @@ `distance` to can specify the CSS Selector or scroll position. | ||
console.log("Complete!!", isCancel); | ||
}, | ||
// Each animation frame | ||
stepScroll(currentTime, props) { | ||
console.log("step", currentTime, props); | ||
} | ||
@@ -457,3 +464,4 @@ }); | ||
// Stop scrolling case of trigger element that contains the `is-disabled` class. | ||
if (trigger.classList.contains("is-disabled")) { | ||
console.log("Before!!"); | ||
if (trigger && trigger.classList.contains("is-disabled")) { | ||
return false; | ||
@@ -474,2 +482,6 @@ } | ||
} | ||
stepScroll(currentTime, props) { | ||
console.log("step", currentTime, props); | ||
} | ||
} | ||
@@ -476,0 +488,0 @@ ``` |
@@ -8,3 +8,3 @@ /*! | ||
* @license MIT | ||
* @version 0.6.2 | ||
* @version 0.7.0 | ||
*/ | ||
@@ -586,2 +586,3 @@ (function (global, factory) { | ||
this.props = {}; | ||
this.options = {}; | ||
this.progress = false; | ||
@@ -593,13 +594,9 @@ this.startTime = null; | ||
key: "run", | ||
value: function run(x, y, duration, delay, easing) { | ||
value: function run(x, y, options) { | ||
var _this = this; | ||
var callback = arguments.length <= 5 || arguments[5] === undefined ? function () {} : arguments[5]; | ||
if (this.progress) return; | ||
this.props = { x: x, y: y }; | ||
this.duration = duration; | ||
this.delay = delay; | ||
this.easing = easing.replace("ease", ""); | ||
this.callback = callback; | ||
this.options = options; | ||
this.options.easing = options.easing.replace("ease", ""); | ||
this.progress = true; | ||
@@ -615,3 +612,3 @@ | ||
}); | ||
}, delay); | ||
}, this.options.delay); | ||
} | ||
@@ -622,2 +619,3 @@ }, { | ||
var gotoEnd = arguments.length <= 0 || arguments[0] === undefined ? true : arguments[0]; | ||
var complete = this.options.complete; | ||
@@ -632,5 +630,5 @@ this.startTime = null; | ||
if (isFunction(this.callback)) { | ||
this.callback(); | ||
this.callback = null; | ||
if (isFunction(complete)) { | ||
complete.call(this); | ||
this.options.complete = null; | ||
} | ||
@@ -654,8 +652,10 @@ } | ||
var props = this.props; | ||
var duration = this.duration; | ||
var options = this.options; | ||
var startTime = this.startTime; | ||
var startProps = this.startProps; | ||
var duration = options.duration; | ||
var step = options.step; | ||
var toProps = {}; | ||
var easing = Easing[this.easing]; | ||
var easing = Easing[this.options.easing]; | ||
var timeElapsed = time - startTime; | ||
@@ -677,5 +677,10 @@ var t = Math.min(1, Math.max(timeElapsed / duration, 0)); | ||
timeElapsed <= duration ? raf(function (time) { | ||
return _this2._loop(time); | ||
}) : this.stop(true); | ||
if (timeElapsed <= duration) { | ||
step.call(this, t, toProps); | ||
raf(function (time) { | ||
return _this2._loop(time); | ||
}); | ||
} else { | ||
this.stop(true); | ||
} | ||
} | ||
@@ -813,23 +818,31 @@ }]); | ||
// Run the animation!! | ||
this.tween.run(scroll.left, scroll.top, params.duration, params.delay, params.easing, function () { | ||
// Update URL | ||
if (hash != null && hash !== window.location.hash && params.updateURL) { | ||
_this2.updateURLHash(hash); | ||
} | ||
this.tween.run(scroll.left, scroll.top, { | ||
duration: params.duration, | ||
delay: params.delay, | ||
easing: params.easing, | ||
complete: function complete() { | ||
// Update URL | ||
if (hash != null && hash !== window.location.hash && params.updateURL) { | ||
_this2.updateURLHash(hash); | ||
} | ||
// Unbind the scroll stop events, And call `afterScroll` or `cancelScroll` | ||
_this2.unbindContainerStop(); | ||
// Unbind the scroll stop events, And call `afterScroll` or `cancelScroll` | ||
_this2.unbindContainerStop(); | ||
// Remove the temporary options | ||
_this2._options = null; | ||
// Remove the temporary options | ||
_this2._options = null; | ||
// Call `cancelScroll` or `afterScroll` | ||
if (_this2._shouldCallCancelScroll) { | ||
_this2.hook(params, "cancelScroll"); | ||
} else { | ||
_this2.hook(params, "afterScroll", scroll, trigger); | ||
// Call `cancelScroll` or `afterScroll` | ||
if (_this2._shouldCallCancelScroll) { | ||
_this2.hook(params, "cancelScroll"); | ||
} else { | ||
_this2.hook(params, "afterScroll", scroll, trigger); | ||
} | ||
// Call `completeScroll` | ||
_this2.hook(params, "completeScroll", _this2._shouldCallCancelScroll); | ||
}, | ||
step: function step(currentTime, props) { | ||
_this2.hook(params, "stepScroll", currentTime, props); | ||
} | ||
// Call `completeScroll` | ||
_this2.hook(params, "completeScroll", _this2._shouldCallCancelScroll); | ||
}); | ||
@@ -1001,2 +1014,13 @@ | ||
/** | ||
* Called at each animation frame of the scroll. | ||
* @param {Float} | ||
* @param {Object} | ||
* @return {Void} | ||
*/ | ||
}, { | ||
key: "stepScroll", | ||
value: function stepScroll(currentTime, props) {} | ||
/** | ||
* Parse the value of coordinate | ||
@@ -1326,3 +1350,4 @@ * @param {Any} | ||
cancelScroll: null, | ||
completeScroll: null | ||
completeScroll: null, | ||
stepScroll: null | ||
}; | ||
@@ -1329,0 +1354,0 @@ |
@@ -8,4 +8,4 @@ /*! | ||
* @license MIT | ||
* @version 0.6.2 | ||
* @version 0.7.0 | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?t+"":"object"===("undefined"==typeof t?"undefined":lt["typeof"](t))||"function"==typeof t?ct[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":lt["typeof"](t)}function n(t){return Array.isArray(t)}function e(t){var n=null==t?null:t.length;return o(n)&&n>=0&&ut>=n}function i(e){return!n(e)&&"object"===t(e)}function o(n){return"number"===t(n)}function r(n){return"string"===t(n)}function l(n){return"function"===t(n)}function u(t){return!n(t)&&t-parseFloat(t)+1>=0}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;n>i;i++)e[i-1]=arguments[i];return s(e,function(n){s(n,function(n,e){t[e]=n})}),t}function s(t,n,o){if(null==t)return t;if(o=o||t,i(t)){for(var r in t)if(a(t,r)&&n.call(o,t[r],r)===!1)break}else if(e(t)){var l=void 0,u=t.length;for(l=0;u>l&&n.call(o,t[l],l)!==!1;l++);}return t}function h(t){return t.replace(/\s*/g,"")||""}function f(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?document:n).querySelector(t)}function d(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?document:n).querySelectorAll(t)}function p(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),i=e.length;--i>=0&&e.item(i)!==t;);return i>-1}function v(t){var n=document;return t===n.documentElement||t===n.body}function g(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],i=st[n],o=t instanceof Element?[t]:d(t),r=[],l=document.createElement("div"),u=0;u<o.length;u++){var a=o[u];if(a[i]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[i]=1,a[i]>0&&r.push(a),a[i]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function y(t,n){var e=g(t,n,!1);return e.length>=1?e[0]:void 0}function m(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function S(t){return Math.max(t.scrollHeight,t.clientHeight,t.offsetHeight)}function C(t){return Math.max(t.scrollWidth,t.clientWidth,t.offsetWidth)}function w(t){return{width:C(t),height:S(t)}}function k(){return{width:Math.max(C(document.body),C(document.documentElement)),height:Math.max(S(document.body),S(document.documentElement))}}function b(t){return v(t)?{viewport:{width:Math.min(window.innerWidth,document.documentElement.clientWidth),height:window.innerHeight},size:k()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:w(t)}}function O(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=m(t);return e?e[ht[n]]:t[st[n]]}function x(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],i=m(t),o="y"===e;i?i.scrollTo(o?i[ht.x]:n,o?n:i[ht.y]):t[st[e]]=n}function _(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var i={},o=void 0;if(null==n||v(n))o=t.ownerDocument.documentElement,i.top=window.pageYOffset,i.left=window.pageXOffset;else{o=n;var r=o.getBoundingClientRect();i.top=-1*r.top+o.scrollTop,i.left=-1*r.left+o.scrollLeft}return{top:e.top+i.top-o.clientTop,left:e.left+i.left-o.clientLeft}}return e}function I(t,n,e){var i=n.split(",");i.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function L(t,n,e){var i=n.split(",");i.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function E(t){return t}function M(t,n,e,i,o){return i*(n/=o)*n+e}function A(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function z(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n+e:-i/2*(--n*(n-2)-1)+e}function T(t,n,e,i,o){return i*(n/=o)*n*n+e}function D(t,n,e,i,o){return i*((n=n/o-1)*n*n+1)+e}function Q(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n+e:i/2*((n-=2)*n*n+2)+e}function j(t,n,e,i,o){return i*(n/=o)*n*n*n+e}function B(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function P(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n+e:-i/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function H(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function W(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n*n*n*n+e:i/2*((n-=2)*n*n*n*n+2)+e}function q(t,n,e,i,o){return-i*pt(n/o*(Ct/2))+i+e}function F(t,n,e,i,o){return i*vt(n/o*(Ct/2))+e}function U(t,n,e,i,o){return-i/2*(pt(Ct*n/o)-1)+e}function $(t,n,e,i,o){return 0===n?e:i*gt(2,10*(n/o-1))+e}function N(t,n,e,i,o){return n===o?e+i:i*(-gt(2,-10*n/o)+1)+e}function X(t,n,e,i,o){return 0===n?e:n===o?e+i:(n/=o/2)<1?i/2*gt(2,10*(n-1))+e:i/2*(-gt(2,-10*--n)+2)+e}function Y(t,n,e,i,o){return-i*(mt(1-(n/=o)*n)-1)+e}function J(t,n,e,i,o){return i*mt(1-(n=n/o-1)*n)+e}function V(t,n,e,i,o){return(n/=o/2)<1?-i/2*(mt(1-n*n)-1)+e:i/2*(mt(1-(n-=2)*n)+1)+e}function G(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<yt(i)?(u=i,r=l/4):r=l/(2*Ct)*St(i/u),-(u*gt(2,10*(n-=1))*vt((n*o-r)*(2*Ct)/l))+e)}function K(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:1===(n/=o)?e+i:(l||(l=.3*o),u<yt(i)?(u=i,r=l/4):r=l/(2*Ct)*St(i/u),u*gt(2,-10*n)*vt((n*o-r)*(2*Ct)/l)+i+e)}function Z(t,n,e,i,o){var r=1.70158,l=0,u=i;return 0===n?e:2===(n/=o/2)?e+i:(l||(l=o*(.3*1.5)),u<yt(i)?(u=i,r=l/4):r=l/(2*Ct)*St(i/u),1>n?-.5*(u*gt(2,10*(n-=1))*vt((n*o-r)*(2*Ct)/l))+e:u*gt(2,-10*(n-=1))*vt((n*o-r)*(2*Ct)/l)*.5+i+e)}function tt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*(n/=o)*n*((r+1)*n-r)+e}function nt(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return i*((n=n/o-1)*n*((r+1)*n+r)+1)+e}function et(t,n,e,i,o){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=o/2)<1?i/2*(n*n*(((r*=1.525)+1)*n-r))+e:i/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function it(t,n,e,i,o){return i-ot(t,o-n,0,i,o)+e}function ot(t,n,e,i,o){return(n/=o)<1/2.75?i*(7.5625*n*n)+e:2/2.75>n?i*(7.5625*(n-=1.5/2.75)*n+.75)+e:2.5/2.75>n?i*(7.5625*(n-=2.25/2.75)*n+.9375)+e:i*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function rt(t,n,e,i,o){return o/2>n?.5*it(t,2*n,0,i,o)+e:.5*ot(t,2*n-o,0,i,o)+.5*i+e}var lt={};lt["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},lt.classCallCheck=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},lt.createClass=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}();var ut=Math.pow(2,53)-1,at=["Boolean","Number","String","Function","Array","Object"],ct={};at.forEach(function(t){ct["[object "+t+"]"]=t.toLowerCase()});var st={y:"scrollTop",x:"scrollLeft"},ht={y:"pageYOffset",x:"pageXOffset"},ft=function(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history&&"file:"!==window.location.protocol:!1}(),dt=Math,pt=dt.cos,vt=dt.sin,gt=dt.pow,yt=dt.abs,mt=dt.sqrt,St=dt.asin,Ct=dt.PI,wt=Object.freeze({linear:E,InQuad:M,OutQuad:A,InOutQuad:z,InCubic:T,OutCubic:D,InOutCubic:Q,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:W,InSine:q,OutSine:F,InOutSine:U,InExpo:$,OutExpo:N,InOutExpo:X,InCirc:Y,OutCirc:J,InOutCirc:V,InElastic:G,OutElastic:K,InOutElastic:Z,InBack:tt,OutBack:nt,InOutBack:et,InBounce:it,OutBounce:ot,InOutBounce:rt}),kt=0,bt=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var n=Date.now(),e=Math.max(0,16-(n-kt)),i=window.setTimeout(function(){t(n+e)},e);return kt=n+e,i},Ot=function(){function t(n){lt.classCallCheck(this,t),this.el=n,this.props={},this.progress=!1,this.startTime=null}return lt.createClass(t,[{key:"run",value:function(t,n,e,i,o){var r=this,l=arguments.length<=5||void 0===arguments[5]?function(){}:arguments[5];this.progress||(this.props={x:t,y:n},this.duration=e,this.delay=i,this.easing=o.replace("ease",""),this.callback=l,this.progress=!0,setTimeout(function(){r.startProps={x:O(r.el,"x"),y:O(r.el,"y")},bt(function(t){return r._loop(t)})},i))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];this.startTime=null,this.progress=!1,t&&(x(this.el,this.props.x,"x"),x(this.el,this.props.y,"y")),l(this.callback)&&(this.callback(),this.callback=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,i=this.props,o=this.duration,r=this.startTime,l=this.startProps,u={},a=wt[this.easing],c=t-r,h=Math.min(1,Math.max(c/o,0));s(i,function(t,n){var e=l[n],i=t-e;if(0===i)return!0;var r=a(h,o*h,0,1,o);u[n]=Math.round(e+i*r)}),s(u,function(t,n){x(e,t,n)}),o>=c?bt(function(t){return n._loop(t)}):this.stop(!0)}}]),t}(),xt=window,_t=document,It="onwheel"in _t?"wheel":"onmousewheel"in _t?"mousewheel":"DOMMouseScroll",Lt=It+", touchstart, touchmove",Et="DOMContentLoaded",Mt=!1;I(_t,Et,function(){Mt=!0});var At=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],i=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];lt.classCallCheck(this,t);var o=c({},t.defaults,e);this.options=o,this.getContainer(i,function(t){n.container=t,n.header=f(o.header),n.tween=new Ot(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(o,"initialized")})}return lt.createClass(t,[{key:"to",value:function(t){var n=this,e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=this.container,o=this.header,l=c({},this.options,e);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,s=this.parseCoodinate(t),h=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),i){if(!s&&r(t))if(h=/^#/.test(t)?t:null,"#"===t)s={top:0,left:0};else{var d=f(t),p=_(d,i);if(!p)return;s=p}if(s){u&&(s.top+=u.top,s.left+=u.left),o&&(s.top=Math.max(0,s.top-w(o).height));var v=b(i),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",s,a)!==!1&&(s.top=l.verticalScroll?Math.max(0,Math.min(y.height-g.height,s.top)):O(i,"y"),s.left=l.horizontalScroll?Math.max(0,Math.min(y.width-g.width,s.left)):O(i,"x"),this.tween.run(s.left,s.top,l.duration,l.delay,l.easing,function(){null!=h&&h!==window.location.hash&&l.updateURL&&n.updateURLHash(h),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",s,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,c({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,c({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=_(t,this.container);this.to(e,c({},n))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!0),this.tween.stop(t)}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.options=c({},this.options,t),this.header=f(this.options.header),this.bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"parseCoodinate",value:function(t){var e=this._options?this._options.verticalScroll:this.options.verticalScroll,i={top:0,left:0};if(a(t,"top")||a(t,"left"))i=c(i,t);else if(n(t))2===t.length?(i.top=t[0],i.left=t[1]):(i.top=e?t[0]:0,i.left=e?0:t[0]);else if(u(t))i.top=e?t:0,i.left=e?0:t;else{if(!r(t))return null;if(t=h(t),/^\d+,\d+$/.test(t))t=t.split(","),i.top=t[0],i.left=t[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(t)){var o=t.match(/top:(\d+)/),l=t.match(/left:(\d+)/);i.top=o?o[1]:0,i.left=l?l[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(t))return null;var s=O(this.container,e?"y":"x"),f=t.match(/^(\+|-)\=(\d+)$/),d=f[1],p=parseInt(f[2],10);"+"===d?(i.top=e?s+p:0,i.left=e?0:s+p):(i.top=e?s-p:0,i.left=e?0:s-p)}}return i.top=parseInt(i.top,10),i.left=parseInt(i.left,10),i}},{key:"updateURLHash",value:function(t){ft&&window.history.pushState(null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,i=this.options,o=i.verticalScroll,r=i.horizontalScroll,l=void 0;o&&(l=y(t,"y")),!l&&r&&(l=y(t,"x")),l||Mt?n.call(this,l):!function(){var i=!1;I(_t,Et,function(){i=!0,e.getContainer(t,n)}),I(xt,"load",function(){i||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),I(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(L(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),I(t,Lt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,Lt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],i=arguments.length,o=Array(i>2?i-2:0),r=2;i>r;r++)o[r-2]=arguments[r];if(l(e)){var u=e.apply(this,o);if(void 0!==u)return u}return this[n].apply(this,o)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==_t;e=e.parentNode)if(p(e,n.trigger)){var i=e.getAttribute("data-scroll"),o=this.parseDataOptions(e),r=i||e.getAttribute("href");n=c({},n,o),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return At.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null},At}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.SweetScroll=n()}(this,function(){"use strict";function t(t){return null==t?t+"":"object"===("undefined"==typeof t?"undefined":lt["typeof"](t))||"function"==typeof t?ct[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":lt["typeof"](t)}function n(t){return Array.isArray(t)}function e(t){var n=null==t?null:t.length;return i(n)&&n>=0&&ut>=n}function o(e){return!n(e)&&"object"===t(e)}function i(n){return"number"===t(n)}function r(n){return"string"===t(n)}function l(n){return"function"===t(n)}function u(t){return!n(t)&&t-parseFloat(t)+1>=0}function a(t,n){return t&&t.hasOwnProperty(n)}function c(t){for(var n=arguments.length,e=Array(n>1?n-1:0),o=1;n>o;o++)e[o-1]=arguments[o];return s(e,function(n){s(n,function(n,e){t[e]=n})}),t}function s(t,n,i){if(null==t)return t;if(i=i||t,o(t)){for(var r in t)if(a(t,r)&&n.call(i,t[r],r)===!1)break}else if(e(t)){var l=void 0,u=t.length;for(l=0;u>l&&n.call(i,t[l],l)!==!1;l++);}return t}function h(t){return t.replace(/\s*/g,"")||""}function f(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?document:n).querySelector(t)}function p(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==n?document:n).querySelectorAll(t)}function d(t,n){for(var e=(t.document||t.ownerDocument).querySelectorAll(n),o=e.length;--o>=0&&e.item(o)!==t;);return o>-1}function v(t){var n=document;return t===n.documentElement||t===n.body}function g(t){for(var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],o=st[n],i=t instanceof Element?[t]:p(t),r=[],l=document.createElement("div"),u=0;u<i.length;u++){var a=i[u];if(a[o]>0?r.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[o]=1,a[o]>0&&r.push(a),a[o]=0,a.removeChild(l)),!e&&r.length>0)break}return r}function y(t,n){var e=g(t,n,!1);return e.length>=1?e[0]:void 0}function m(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function S(t){return Math.max(t.scrollHeight,t.clientHeight,t.offsetHeight)}function C(t){return Math.max(t.scrollWidth,t.clientWidth,t.offsetWidth)}function w(t){return{width:C(t),height:S(t)}}function k(){return{width:Math.max(C(document.body),C(document.documentElement)),height:Math.max(S(document.body),S(document.documentElement))}}function b(t){return v(t)?{viewport:{width:Math.min(window.innerWidth,document.documentElement.clientWidth),height:window.innerHeight},size:k()}:{viewport:{width:t.clientWidth,height:t.clientHeight},size:w(t)}}function O(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=m(t);return e?e[ht[n]]:t[st[n]]}function x(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],o=m(t),i="y"===e;o?o.scrollTo(i?o[ht.x]:n,i?n:o[ht.y]):t[st[e]]=n}function _(t){var n=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var e=t.getBoundingClientRect();if(e.width||e.height){var o={},i=void 0;if(null==n||v(n))i=t.ownerDocument.documentElement,o.top=window.pageYOffset,o.left=window.pageXOffset;else{i=n;var r=i.getBoundingClientRect();o.top=-1*r.top+i.scrollTop,o.left=-1*r.left+i.scrollLeft}return{top:e.top+o.top-i.clientTop,left:e.left+o.left-i.clientLeft}}return e}function I(t,n,e){var o=n.split(",");o.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function L(t,n,e){var o=n.split(",");o.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function E(t){return t}function M(t,n,e,o,i){return o*(n/=i)*n+e}function A(t,n,e,o,i){return-o*(n/=i)*(n-2)+e}function z(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n+e:-o/2*(--n*(n-2)-1)+e}function T(t,n,e,o,i){return o*(n/=i)*n*n+e}function D(t,n,e,o,i){return o*((n=n/i-1)*n*n+1)+e}function Q(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n*n+e:o/2*((n-=2)*n*n+2)+e}function j(t,n,e,o,i){return o*(n/=i)*n*n*n+e}function B(t,n,e,o,i){return-o*((n=n/i-1)*n*n*n-1)+e}function P(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n*n*n+e:-o/2*((n-=2)*n*n*n-2)+e}function R(t,n,e,o,i){return o*(n/=i)*n*n*n*n+e}function H(t,n,e,o,i){return o*((n=n/i-1)*n*n*n*n+1)+e}function W(t,n,e,o,i){return(n/=i/2)<1?o/2*n*n*n*n*n+e:o/2*((n-=2)*n*n*n*n+2)+e}function q(t,n,e,o,i){return-o*dt(n/i*(Ct/2))+o+e}function F(t,n,e,o,i){return o*vt(n/i*(Ct/2))+e}function U(t,n,e,o,i){return-o/2*(dt(Ct*n/i)-1)+e}function $(t,n,e,o,i){return 0===n?e:o*gt(2,10*(n/i-1))+e}function N(t,n,e,o,i){return n===i?e+o:o*(-gt(2,-10*n/i)+1)+e}function X(t,n,e,o,i){return 0===n?e:n===i?e+o:(n/=i/2)<1?o/2*gt(2,10*(n-1))+e:o/2*(-gt(2,-10*--n)+2)+e}function Y(t,n,e,o,i){return-o*(mt(1-(n/=i)*n)-1)+e}function J(t,n,e,o,i){return o*mt(1-(n=n/i-1)*n)+e}function V(t,n,e,o,i){return(n/=i/2)<1?-o/2*(mt(1-n*n)-1)+e:o/2*(mt(1-(n-=2)*n)+1)+e}function G(t,n,e,o,i){var r=1.70158,l=0,u=o;return 0===n?e:1===(n/=i)?e+o:(l||(l=.3*i),u<yt(o)?(u=o,r=l/4):r=l/(2*Ct)*St(o/u),-(u*gt(2,10*(n-=1))*vt((n*i-r)*(2*Ct)/l))+e)}function K(t,n,e,o,i){var r=1.70158,l=0,u=o;return 0===n?e:1===(n/=i)?e+o:(l||(l=.3*i),u<yt(o)?(u=o,r=l/4):r=l/(2*Ct)*St(o/u),u*gt(2,-10*n)*vt((n*i-r)*(2*Ct)/l)+o+e)}function Z(t,n,e,o,i){var r=1.70158,l=0,u=o;return 0===n?e:2===(n/=i/2)?e+o:(l||(l=i*(.3*1.5)),u<yt(o)?(u=o,r=l/4):r=l/(2*Ct)*St(o/u),1>n?-.5*(u*gt(2,10*(n-=1))*vt((n*i-r)*(2*Ct)/l))+e:u*gt(2,-10*(n-=1))*vt((n*i-r)*(2*Ct)/l)*.5+o+e)}function tt(t,n,e,o,i){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return o*(n/=i)*n*((r+1)*n-r)+e}function nt(t,n,e,o,i){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return o*((n=n/i-1)*n*((r+1)*n+r)+1)+e}function et(t,n,e,o,i){var r=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=i/2)<1?o/2*(n*n*(((r*=1.525)+1)*n-r))+e:o/2*((n-=2)*n*(((r*=1.525)+1)*n+r)+2)+e}function ot(t,n,e,o,i){return o-it(t,i-n,0,o,i)+e}function it(t,n,e,o,i){return(n/=i)<1/2.75?o*(7.5625*n*n)+e:2/2.75>n?o*(7.5625*(n-=1.5/2.75)*n+.75)+e:2.5/2.75>n?o*(7.5625*(n-=2.25/2.75)*n+.9375)+e:o*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function rt(t,n,e,o,i){return i/2>n?.5*ot(t,2*n,0,o,i)+e:.5*it(t,2*n-i,0,o,i)+.5*o+e}var lt={};lt["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},lt.classCallCheck=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},lt.createClass=function(){function t(t,n){for(var e=0;e<n.length;e++){var o=n[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(n,e,o){return e&&t(n.prototype,e),o&&t(n,o),n}}();var ut=Math.pow(2,53)-1,at=["Boolean","Number","String","Function","Array","Object"],ct={};at.forEach(function(t){ct["[object "+t+"]"]=t.toLowerCase()});var st={y:"scrollTop",x:"scrollLeft"},ht={y:"pageYOffset",x:"pageXOffset"},ft=function(){var t=navigator.userAgent;return-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone")?window.history&&"pushState"in window.history&&"file:"!==window.location.protocol:!1}(),pt=Math,dt=pt.cos,vt=pt.sin,gt=pt.pow,yt=pt.abs,mt=pt.sqrt,St=pt.asin,Ct=pt.PI,wt=Object.freeze({linear:E,InQuad:M,OutQuad:A,InOutQuad:z,InCubic:T,OutCubic:D,InOutCubic:Q,InQuart:j,OutQuart:B,InOutQuart:P,InQuint:R,OutQuint:H,InOutQuint:W,InSine:q,OutSine:F,InOutSine:U,InExpo:$,OutExpo:N,InOutExpo:X,InCirc:Y,OutCirc:J,InOutCirc:V,InElastic:G,OutElastic:K,InOutElastic:Z,InBack:tt,OutBack:nt,InOutBack:et,InBounce:ot,OutBounce:it,InOutBounce:rt}),kt=0,bt=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var n=Date.now(),e=Math.max(0,16-(n-kt)),o=window.setTimeout(function(){t(n+e)},e);return kt=n+e,o},Ot=function(){function t(n){lt.classCallCheck(this,t),this.el=n,this.props={},this.options={},this.progress=!1,this.startTime=null}return lt.createClass(t,[{key:"run",value:function(t,n,e){var o=this;this.progress||(this.props={x:t,y:n},this.options=e,this.options.easing=e.easing.replace("ease",""),this.progress=!0,setTimeout(function(){o.startProps={x:O(o.el,"x"),y:O(o.el,"y")},bt(function(t){return o._loop(t)})},this.options.delay))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0],n=this.options.complete;this.startTime=null,this.progress=!1,t&&(x(this.el,this.props.x,"x"),x(this.el,this.props.y,"y")),l(n)&&(n.call(this),this.options.complete=null)}},{key:"_loop",value:function(t){var n=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var e=this.el,o=this.props,i=this.options,r=this.startTime,l=this.startProps,u=i.duration,a=i.step,c={},h=wt[this.options.easing],f=t-r,p=Math.min(1,Math.max(f/u,0));s(o,function(t,n){var e=l[n],o=t-e;if(0===o)return!0;var i=h(p,u*p,0,1,u);c[n]=Math.round(e+o*i)}),s(c,function(t,n){x(e,t,n)}),u>=f?(a.call(this,p,c),bt(function(t){return n._loop(t)})):this.stop(!0)}}]),t}(),xt=window,_t=document,It="onwheel"in _t?"wheel":"onmousewheel"in _t?"mousewheel":"DOMMouseScroll",Lt=It+", touchstart, touchmove",Et="DOMContentLoaded",Mt=!1;I(_t,Et,function(){Mt=!0});var At=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],o=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];lt.classCallCheck(this,t);var i=c({},t.defaults,e);this.options=i,this.getContainer(o,function(t){n.container=t,n.header=f(i.header),n.tween=new Ot(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.hook(i,"initialized")})}return lt.createClass(t,[{key:"to",value:function(t){var n=this,e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],o=this.container,i=this.header,l=c({},this.options,e);this._options=l;var u=this.parseCoodinate(l.offset),a=this._trigger,s=this.parseCoodinate(t),h=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),o){if(!s&&r(t))if(h=/^#/.test(t)?t:null,"#"===t)s={top:0,left:0};else{var p=f(t),d=_(p,o);if(!d)return;s=d}if(s){u&&(s.top+=u.top,s.left+=u.left),i&&(s.top=Math.max(0,s.top-w(i).height));var v=b(o),g=v.viewport,y=v.size;this.hook(l,"beforeScroll",s,a)!==!1&&(s.top=l.verticalScroll?Math.max(0,Math.min(y.height-g.height,s.top)):O(o,"y"),s.left=l.horizontalScroll?Math.max(0,Math.min(y.width-g.width,s.left)):O(o,"x"),this.tween.run(s.left,s.top,{duration:l.duration,delay:l.delay,easing:l.easing,complete:function(){null!=h&&h!==window.location.hash&&l.updateURL&&n.updateURLHash(h),n.unbindContainerStop(),n._options=null,n._shouldCallCancelScroll?n.hook(l,"cancelScroll"):n.hook(l,"afterScroll",s,a),n.hook(l,"completeScroll",n._shouldCallCancelScroll)},step:function(t,e){n.hook(l,"stepScroll",t,e)}}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,c({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,c({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof Element){var e=_(t,this.container);this.to(e,c({},n))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[0];this._stopScrollListener&&(this._shouldCallCancelScroll=!0),this.tween.stop(t)}},{key:"update",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.options=c({},this.options,t),this.header=f(this.options.header),this.bindContainerClick()}},{key:"destroy",value:function(){this.stop(),this.unbindContainerClick(),this.unbindContainerStop(),this.container=null,this.header=null,this.tween=null}},{key:"initialized",value:function(){}},{key:"beforeScroll",value:function(t,n){return!0}},{key:"cancelScroll",value:function(){}},{key:"afterScroll",value:function(t,n){}},{key:"completeScroll",value:function(t){}},{key:"stepScroll",value:function(t,n){}},{key:"parseCoodinate",value:function(t){var e=this._options?this._options.verticalScroll:this.options.verticalScroll,o={top:0,left:0};if(a(t,"top")||a(t,"left"))o=c(o,t);else if(n(t))2===t.length?(o.top=t[0],o.left=t[1]):(o.top=e?t[0]:0,o.left=e?0:t[0]);else if(u(t))o.top=e?t:0,o.left=e?0:t;else{if(!r(t))return null;if(t=h(t),/^\d+,\d+$/.test(t))t=t.split(","),o.top=t[0],o.left=t[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(t)){var i=t.match(/top:(\d+)/),l=t.match(/left:(\d+)/);o.top=i?i[1]:0,o.left=l?l[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(t))return null;var s=O(this.container,e?"y":"x"),f=t.match(/^(\+|-)\=(\d+)$/),p=f[1],d=parseInt(f[2],10);"+"===p?(o.top=e?s+d:0,o.left=e?0:s+d):(o.top=e?s-d:0,o.left=e?0:s-d)}}return o.top=parseInt(o.top,10),o.left=parseInt(o.left,10),o}},{key:"updateURLHash",value:function(t){ft&&window.history.pushState(null,null,t)}},{key:"getContainer",value:function(t,n){var e=this,o=this.options,i=o.verticalScroll,r=o.horizontalScroll,l=void 0;i&&(l=y(t,"y")),!l&&r&&(l=y(t,"x")),l||Mt?n.call(this,l):!function(){var o=!1;I(_t,Et,function(){o=!0,e.getContainer(t,n)}),I(xt,"load",function(){o||e.getContainer(t,n)})}()}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),I(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(L(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),I(t,Lt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,Lt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t,n){for(var e=t[n],o=arguments.length,i=Array(o>2?o-2:0),r=2;o>r;r++)i[r-2]=arguments[r];if(l(e)){var u=e.apply(this,i);if(void 0!==u)return u}return this[n].apply(this,i)}},{key:"handleStopScroll",value:function(t){var n=this._options?this._options.stopScroll:this.options.stopScroll;n?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==_t;e=e.parentNode)if(d(e,n.trigger)){var o=e.getAttribute("data-scroll"),i=this.parseDataOptions(e),r=o||e.getAttribute("href");n=c({},n,i),n.preventDefault&&t.preventDefault(),n.stopPropagation&&t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(r,n):n.verticalScroll?this.toTop(r,n):n.horizontalScroll&&this.toLeft(r,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return At.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,updateURL:!1,preventDefault:!0,stopPropagation:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null,completeScroll:null,stepScroll:null},At}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67482
1120
540