Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sweet-scroll

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sweet-scroll - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

2

package.json
{
"name": "sweet-scroll",
"version": "0.6.0",
"version": "0.6.1",
"description": "Modern and the sweet smooth scroll library.",

@@ -5,0 +5,0 @@ "main": "sweet-scroll.js",

@@ -8,3 +8,3 @@ /*!

* @license MIT
* @version 0.6.0
* @version 0.6.1
*/

@@ -215,9 +215,46 @@ (function (global, factory) {

function getHeight(el) {
return Math.max(el.scrollHeight, el.clientHeight, el.offsetHeight);
}
function getWidth(el) {
return Math.max(el.scrollWidth, el.clientWidth, el.offsetWidth);
}
function getSize(el) {
return {
width: getWidth(el),
height: getHeight(el)
};
}
function getDocumentSize() {
return {
width: Math.max(getWidth(document.body), getWidth(document.documentElement)),
height: Math.max(getHeight(document.body), getHeight(document.documentElement))
};
}
function getViewportAndElementSizes(el) {
if (isRootContainer(el)) {
return {
viewport: {
width: Math.min(window.innerWidth, document.documentElement.clientWidth),
height: window.innerHeight
},
size: getDocumentSize()
};
}
return {
viewport: { width: el.clientWidth, height: el.clientHeight },
size: getSize(el)
};
}
function getScroll(el) {
var direction = arguments.length <= 1 || arguments[1] === undefined ? "y" : arguments[1];
var method = directionMethodMap[direction];
var prop = directionPropMap[direction];
var win = getWindow(el);
return win ? win[prop] : el[method];
return win ? win[directionPropMap[direction]] : el[directionMethodMap[direction]];
}

@@ -228,9 +265,8 @@

var method = directionMethodMap[direction];
var win = getWindow(el);
var top = direction === "y";
if (win) {
win.scrollTo(!top ? offset : win.pageXOffset, top ? offset : win.pageYOffset);
win.scrollTo(!top ? offset : win[directionPropMap.x], top ? offset : win[directionPropMap.y]);
} else {
el[method] = offset;
el[directionMethodMap[direction]] = offset;
}

@@ -681,3 +717,3 @@ }

_this.initialized();
_this.hook(params.initialized);
_this.hook(params, "initialized");
});

@@ -707,2 +743,6 @@ }

var params = merge({}, this.options, options);
// Temporary options
this._options = params;
var offset = this.parseCoodinate(params.offset);

@@ -749,19 +789,16 @@ var trigger = this._trigger;

if (header) {
scroll.top = Math.max(0, scroll.top - this.header.clientHeight);
scroll.top = Math.max(0, scroll.top - getSize(header).height);
}
// Determine the final scroll coordinates
var frameSize = void 0;
var size = void 0;
if (isRootContainer(container)) {
frameSize = { width: win.innerWidth, height: win.innerHeight };
size = { width: doc.body.scrollWidth, height: doc.body.scrollHeight };
} else {
frameSize = { width: container.clientWidth, height: container.clientHeight };
size = { width: container.scrollWidth, height: container.scrollHeight };
}
var _Dom$getViewportAndEl = getViewportAndElementSizes(container);
var viewport = _Dom$getViewportAndEl.viewport;
var size = _Dom$getViewportAndEl.size;
// Call `beforeScroll`
// Stop scrolling when it returns false
if (this.hook(params.beforeScroll, scroll, trigger) === false || this.beforeScroll(scroll, trigger) === false) {
if (this.hook(params, "beforeScroll", scroll, trigger) === false) {
return;

@@ -771,16 +808,5 @@ }

// Adjustment of the maximum value
// vertical
if (params.verticalScroll) {
scroll.top = Math.max(0, Math.min(size.height - frameSize.height, scroll.top));
} else {
scroll.top = getScroll(container, "y");
}
scroll.top = params.verticalScroll ? Math.max(0, Math.min(size.height - viewport.height, scroll.top)) : getScroll(container, "y");
scroll.left = params.horizontalScroll ? Math.max(0, Math.min(size.width - viewport.width, scroll.left)) : getScroll(container, "x");
// horizontal
if (params.horizontalScroll) {
scroll.left = Math.max(0, Math.min(size.width - frameSize.width, scroll.left));
} else {
scroll.left = getScroll(container, "x");
}
// Run the animation!!

@@ -796,13 +822,14 @@ this.tween.run(scroll.left, scroll.top, params.duration, params.delay, params.easing, function () {

// Remove the temporary options
_this2._options = null;
// Call `cancelScroll` or `afterScroll`
if (_this2._shouldCallCancelScroll) {
_this2.hook(params.cancelScroll);
_this2.cancelScroll();
_this2.hook(params, "cancelScroll");
} else {
_this2.hook(params.afterScroll, scroll, trigger);
_this2.afterScroll(scroll, trigger);
_this2.hook(params, "afterScroll", scroll, trigger);
}
// Call `completeScroll`
_this2.hook(params.completeScroll, _this2._shouldCallCancelScroll);
_this2.completeScroll(_this2._shouldCallCancelScroll);
_this2.hook(params, "completeScroll", _this2._shouldCallCancelScroll);
});

@@ -982,3 +1009,3 @@

value: function parseCoodinate(coodinate) {
var enableTop = this.options.verticalScroll;
var enableTop = this._options ? this._options.verticalScroll : this.options.verticalScroll;
var scroll = { top: 0, left: 0 };

@@ -1090,5 +1117,17 @@

if (!container && !isDomContentLoaded) {
addEvent(doc, DOM_CONTENT_LOADED, function () {
_this3.getContainer(selector, callback);
});
(function () {
var isCompleted = false;
addEvent(doc, DOM_CONTENT_LOADED, function () {
isCompleted = true;
_this3.getContainer(selector, callback);
});
// Fallback for DOMContentLoaded
addEvent(win, "load", function () {
if (!isCompleted) {
_this3.getContainer(selector, callback);
}
});
})();
} else {

@@ -1165,3 +1204,4 @@ callback.call(this, container);

* Call the specified callback
* @param {Function}
* @param {Object}
* @param {String}
* @param {...Any}

@@ -1174,10 +1214,18 @@ * @return {Void}

key: "hook",
value: function hook(callback) {
value: function hook(options, type) {
var callback = options[type];
// callback
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
args[_key - 2] = arguments[_key];
}
if (isFunction(callback)) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var result = callback.apply(this, args);
if (result !== undefined) return result;
}
return callback.apply(this, args);
}
// method
return this[type].apply(this, args);
}

@@ -1195,3 +1243,4 @@

value: function handleStopScroll(e) {
if (this.options.stopScroll) {
var stopScroll = this._options ? this._options.stopScroll : this.options.stopScroll;
if (stopScroll) {
this.stop();

@@ -1198,0 +1247,0 @@ } else {

@@ -8,4 +8,4 @@ /*!

* @license MIT
* @version 0.6.0
* @version 0.6.1
*/
!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":nt["typeof"](t))||"function"==typeof t?ot[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":nt["typeof"](t)}function n(t){return Array.isArray(t)}function e(t){var n=null==t?null:t.length;return o(n)&&n>=0&&et>=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 f(t){return t.replace(/\s*/g,"")||""}function h(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=rt[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 S(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function C(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=rt[n],i=lt[n],o=S(t);return o?o[i]:t[e]}function m(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],i=rt[e],o=S(t),r="y"===e;o?o.scrollTo(r?o.pageXOffset:n,r?n:o.pageYOffset):t[i]=n}function k(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 b(t,n,e){var i=n.split(",");i.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function w(t,n,e){var i=n.split(",");i.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function O(t){return t}function x(t,n,e,i,o){return i*(n/=o)*n+e}function I(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function L(t,n,e,i,o){return(n/=o/2)<1?i/2*n*n+e:-i/2*(--n*(n-2)-1)+e}function _(t,n,e,i,o){return i*(n/=o)*n*n+e}function E(t,n,e,i,o){return i*((n=n/o-1)*n*n+1)+e}function A(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 M(t,n,e,i,o){return i*(n/=o)*n*n*n+e}function T(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function z(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 D(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function Q(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function j(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 B(t,n,e,i,o){return-i*at(n/o*(pt/2))+i+e}function P(t,n,e,i,o){return i*ct(n/o*(pt/2))+e}function R(t,n,e,i,o){return-i/2*(at(pt*n/o)-1)+e}function H(t,n,e,i,o){return 0===n?e:i*st(2,10*(n/o-1))+e}function q(t,n,e,i,o){return n===o?e+i:i*(-st(2,-10*n/o)+1)+e}function W(t,n,e,i,o){return 0===n?e:n===o?e+i:(n/=o/2)<1?i/2*st(2,10*(n-1))+e:i/2*(-st(2,-10*--n)+2)+e}function F(t,n,e,i,o){return-i*(ht(1-(n/=o)*n)-1)+e}function U(t,n,e,i,o){return i*ht(1-(n=n/o-1)*n)+e}function $(t,n,e,i,o){return(n/=o/2)<1?-i/2*(ht(1-n*n)-1)+e:i/2*(ht(1-(n-=2)*n)+1)+e}function N(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<ft(i)?(u=i,r=l/4):r=l/(2*pt)*dt(i/u),-(u*st(2,10*(n-=1))*ct((n*o-r)*(2*pt)/l))+e)}function X(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<ft(i)?(u=i,r=l/4):r=l/(2*pt)*dt(i/u),u*st(2,-10*n)*ct((n*o-r)*(2*pt)/l)+i+e)}function Y(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<ft(i)?(u=i,r=l/4):r=l/(2*pt)*dt(i/u),1>n?-.5*(u*st(2,10*(n-=1))*ct((n*o-r)*(2*pt)/l))+e:u*st(2,-10*(n-=1))*ct((n*o-r)*(2*pt)/l)*.5+i+e)}function J(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 V(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 G(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 K(t,n,e,i,o){return i-Z(t,o-n,0,i,o)+e}function Z(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 tt(t,n,e,i,o){return o/2>n?.5*K(t,2*n,0,i,o)+e:.5*Z(t,2*n-o,0,i,o)+.5*i+e}var nt={};nt["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},nt.classCallCheck=function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")},nt.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 et=Math.pow(2,53)-1,it=["Boolean","Number","String","Function","Array","Object"],ot={};it.forEach(function(t){ot["[object "+t+"]"]=t.toLowerCase()});var rt={y:"scrollTop",x:"scrollLeft"},lt={y:"pageYOffset",x:"pageXOffset"},ut=Math,at=ut.cos,ct=ut.sin,st=ut.pow,ft=ut.abs,ht=ut.sqrt,dt=ut.asin,pt=ut.PI,vt=Object.freeze({linear:O,InQuad:x,OutQuad:I,InOutQuad:L,InCubic:_,OutCubic:E,InOutCubic:A,InQuart:M,OutQuart:T,InOutQuart:z,InQuint:D,OutQuint:Q,InOutQuint:j,InSine:B,OutSine:P,InOutSine:R,InExpo:H,OutExpo:q,InOutExpo:W,InCirc:F,OutCirc:U,InOutCirc:$,InElastic:N,OutElastic:X,InOutElastic:Y,InBack:J,OutBack:V,InOutBack:G,InBounce:K,OutBounce:Z,InOutBounce:tt}),gt=0,yt=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var n=Date.now(),e=Math.max(0,16-(n-gt)),i=window.setTimeout(function(){t(n+e)},e);return gt=n+e,i},St=function(){function t(n){nt.classCallCheck(this,t),this.el=n,this.props={},this.progress=!1,this.startTime=null}return nt.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:C(r.el,"x"),y:C(r.el,"y")},yt(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&&(m(this.el,this.props.x,"x"),m(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=vt[this.easing],c=t-r,f=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(f,o*f,0,1,o);u[n]=Math.round(e+i*r)}),s(u,function(t,n){m(e,t,n)}),o>=c?yt(function(t){return n._loop(t)}):this.stop(!0)}}]),t}(),Ct=window,mt=document,kt="onwheel"in mt?"wheel":"onmousewheel"in mt?"mousewheel":"DOMMouseScroll",bt=kt+", touchstart, touchmove",wt="DOMContentLoaded",Ot=!1;b(mt,wt,function(){Ot=!0});var xt=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}(),It=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];nt.classCallCheck(this,t);var o=c({},t.defaults,e);this.options=o,this.getContainer(i,function(t){n.container=t,n.header=h(o.header),n.tween=new St(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.initialized(),n.hook(o.initialized)})}return nt.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),u=this.parseCoodinate(l.offset),a=this._trigger,s=this.parseCoodinate(t),f=null;if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),i){if(!s&&r(t))if(f=/^#/.test(t)?t:null,"#"===t)s={top:0,left:0};else{var d=h(t),p=k(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-this.header.clientHeight));var g=void 0,y=void 0;v(i)?(g={width:Ct.innerWidth,height:Ct.innerHeight},y={width:mt.body.scrollWidth,height:mt.body.scrollHeight}):(g={width:i.clientWidth,height:i.clientHeight},y={width:i.scrollWidth,height:i.scrollHeight}),this.hook(l.beforeScroll,s,a)!==!1&&this.beforeScroll(s,a)!==!1&&(l.verticalScroll?s.top=Math.max(0,Math.min(y.height-g.height,s.top)):s.top=C(i,"y"),l.horizontalScroll?s.left=Math.max(0,Math.min(y.width-g.width,s.left)):s.left=C(i,"x"),this.tween.run(s.left,s.top,l.duration,l.delay,l.easing,function(){null!=f&&f!==window.location.hash&&l.updateURL&&n.updateURLHash(f),n.unbindContainerStop(),n._shouldCallCancelScroll?(n.hook(l.cancelScroll),n.cancelScroll()):(n.hook(l.afterScroll,s,a),n.afterScroll(s,a)),n.hook(l.completeScroll,n._shouldCallCancelScroll),n.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=k(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=h(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.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=f(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=C(this.container,e?"y":"x"),h=t.match(/^(\+|-)\=(\d+)$/),d=h[1],p=parseInt(h[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){xt&&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||Ot?n.call(this,l):b(mt,wt,function(){e.getContainer(t,n)})}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),b(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(w(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),b(t,bt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(w(t,bt,this._stopScrollListener),this._stopScrollListener=null)}},{key:"hook",value:function(t){if(l(t)){for(var n=arguments.length,e=Array(n>1?n-1:0),i=1;n>i;i++)e[i-1]=arguments[i];return t.apply(this,e)}}},{key:"handleStopScroll",value:function(t){this.options.stopScroll?this.stop():t.preventDefault()}},{key:"handleContainerClick",value:function(t){for(var n=this.options,e=t.target;e&&e!==mt;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 It.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},It});
!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 z(t,n,e,i,o){return-i*(n/=o)*(n-2)+e}function A(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*dt(n/o*(St/2))+i+e}function F(t,n,e,i,o){return i*pt(n/o*(St/2))+e}function U(t,n,e,i,o){return-i/2*(dt(St*n/o)-1)+e}function $(t,n,e,i,o){return 0===n?e:i*vt(2,10*(n/o-1))+e}function N(t,n,e,i,o){return n===o?e+i:i*(-vt(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*vt(2,10*(n-1))+e:i/2*(-vt(2,-10*--n)+2)+e}function Y(t,n,e,i,o){return-i*(yt(1-(n/=o)*n)-1)+e}function J(t,n,e,i,o){return i*yt(1-(n=n/o-1)*n)+e}function V(t,n,e,i,o){return(n/=o/2)<1?-i/2*(yt(1-n*n)-1)+e:i/2*(yt(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<gt(i)?(u=i,r=l/4):r=l/(2*St)*mt(i/u),-(u*vt(2,10*(n-=1))*pt((n*o-r)*(2*St)/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<gt(i)?(u=i,r=l/4):r=l/(2*St)*mt(i/u),u*vt(2,-10*n)*pt((n*o-r)*(2*St)/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<gt(i)?(u=i,r=l/4):r=l/(2*St)*mt(i/u),1>n?-.5*(u*vt(2,10*(n-=1))*pt((n*o-r)*(2*St)/l))+e:u*vt(2,-10*(n-=1))*pt((n*o-r)*(2*St)/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=Math,dt=ft.cos,pt=ft.sin,vt=ft.pow,gt=ft.abs,yt=ft.sqrt,mt=ft.asin,St=ft.PI,Ct=Object.freeze({linear:E,InQuad:M,OutQuad:z,InOutQuad:A,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}),wt=0,kt=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var n=Date.now(),e=Math.max(0,16-(n-wt)),i=window.setTimeout(function(){t(n+e)},e);return wt=n+e,i},bt=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")},kt(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=Ct[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?kt(function(t){return n._loop(t)}):this.stop(!0)}}]),t}(),Ot=window,xt=document,_t="onwheel"in xt?"wheel":"onmousewheel"in xt?"mousewheel":"DOMMouseScroll",It=_t+", touchstart, touchmove",Lt="DOMContentLoaded",Et=!1;I(xt,Lt,function(){Et=!0});var Mt=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}(),zt=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 bt(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.initialized(),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){Mt&&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||Et?n.call(this,l):!function(){var i=!1;I(xt,Lt,function(){i=!0,e.getContainer(t,n)}),I(Ot,"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,It,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(L(t,It,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!==xt;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 zt.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},zt});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc