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.3.0 to 0.3.1

54

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

@@ -32,32 +32,34 @@ "main": "sweet-scroll.js",

"devDependencies": {
"babel-eslint": "^4.1.6",
"babel-plugin-espower": "^2.0.0",
"babel-preset-es2015": "^6.1.18",
"babel-preset-es2015-rollup": "^1.0.0",
"babel-preset-stage-0": "^6.1.18",
"babel-eslint": "^6.0.0",
"babel-plugin-espower": "^2.1.2",
"babel-preset-es2015": "^6.6.0",
"babel-preset-es2015-rollup": "^1.1.1",
"babel-preset-stage-0": "^6.5.0",
"babelify": "^7.2.0",
"browser-sync": "^2.10.0",
"gulp": "^3.9.0",
"browser-sync": "^2.11.2",
"browserify": "^13.0.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.0",
"gulp-eslint": "^1.1.1",
"gulp-load-plugins": "^1.1.0",
"gulp-plumber": "^1.0.1",
"gulp-eslint": "^2.0.0",
"gulp-load-plugins": "^1.2.0",
"gulp-plumber": "^1.1.0",
"gulp-rename": "^1.2.2",
"gulp-rollup": "^1.4.0",
"gulp-sass": "^2.1.0",
"gulp-uglify": "^1.5.1",
"karma": "^0.13.15",
"karma-browserify": "^4.4.2",
"karma-fixture": "^0.2.5",
"gulp-rollup": "^1.8.0",
"gulp-sass": "^2.2.0",
"gulp-uglify": "^1.5.3",
"karma": "^0.13.22",
"karma-browserify": "^5.0.3",
"karma-fixture": "^0.2.6",
"karma-html2js-preprocessor": "^0.1.0",
"karma-mocha": "^0.2.1",
"karma-phantomjs-launcher": "^0.2.1",
"karma-phantomjs-shim": "^1.1.2",
"mocha": "^2.4.4",
"phantomjs": "^1.9.19",
"power-assert": "^1.2.0",
"rollup": "^0.21.1",
"rollup-plugin-babel": "^2.2.0",
"run-sequence": "^1.1.5"
"karma-mocha": "^0.2.2",
"karma-phantomjs-launcher": "^1.0.0",
"karma-phantomjs-shim": "^1.2.0",
"mocha": "^2.4.5",
"phantomjs-prebuilt": "^2.1.7",
"power-assert": "^1.3.1",
"rollup": "^0.25.7",
"rollup-plugin-babel": "^2.4.0",
"run-sequence": "^1.1.5",
"watchify": "^3.7.0"
}
}

@@ -6,2 +6,3 @@ sweet-scroll.js

[![npm version](https://img.shields.io/npm/v/sweet-scroll.svg?style=flat-square)](http://badge.fury.io/js/sweet-scroll)
[![David](https://img.shields.io/david/dev/tsuyoshiwada/sweet-scroll.svg?style=flat-square)](https://david-dm.org/tsuyoshiwada/sweet-scroll/#info=devDependencies&view=table)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.githubusercontent.com/tsuyoshiwada/sweet-scroll/master/LICENSE)

@@ -8,0 +9,0 @@

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

* @license MIT
* @version 0.3.0
* @version 0.3.1
*/

@@ -14,3 +14,3 @@ (function (global, factory) {

typeof define === 'function' && define.amd ? define(factory) :
global.SweetScroll = factory();
(global.SweetScroll = factory());
}(this, function () { 'use strict';

@@ -123,3 +123,3 @@

} else if (isArrayLike(obj)) {
var i = undefined,
var i = void 0,
length = obj.length;

@@ -159,16 +159,2 @@ for (i = 0; i < length; i++) {

function addEvent(el, event, listener) {
var events = event.split(",");
events.forEach(function (eventName) {
el.addEventListener(eventName.trim(), listener, false);
});
}
function removeEvent(el, event, listener) {
var events = event.split(",");
events.forEach(function (eventName) {
el.removeEventListener(eventName.trim(), listener, false);
});
}
var directionMethodMap = {

@@ -263,3 +249,3 @@ y: "scrollTop",

var scroll = {};
var ctx = undefined;
var ctx = void 0;
if (context == null || isRootContainer(context)) {

@@ -283,13 +269,15 @@ ctx = el.ownerDocument.documentElement;

var lastTime = 0;
function addEvent(el, event, listener) {
var events = event.split(",");
events.forEach(function (eventName) {
el.addEventListener(eventName.trim(), listener, false);
});
}
var raf = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback) {
var currentTime = Date.now();
var timeToCall = Math.max(0, 16 - (currentTime - lastTime));
var id = window.setTimeout(function () {
callback(currentTime + timeToCall);
}, timeToCall);
lastTime = currentTime + timeToCall;
return id;
};
function removeEvent(el, event, listener) {
var events = event.split(",");
events.forEach(function (eventName) {
el.removeEventListener(eventName.trim(), listener, false);
});
}

@@ -506,3 +494,3 @@ var math = Math;

var Easing = Object.freeze({
var Easing = Object.freeze({
linear: linear,

@@ -541,2 +529,14 @@ InQuad: InQuad,

var lastTime = 0;
var raf = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function (callback) {
var currentTime = Date.now();
var timeToCall = Math.max(0, 16 - (currentTime - lastTime));
var id = window.setTimeout(function () {
callback(currentTime + timeToCall);
}, timeToCall);
lastTime = currentTime + timeToCall;
return id;
};
var ScrollTween = function () {

@@ -645,4 +645,9 @@ function ScrollTween(el) {

var CONTAINER_STOP_EVENTS = WHEEL_EVENT + ", touchstart, touchmove";
var DOM_CONTENT_LOADED = "DOMContentLoaded";
var isDomContentLoaded = false;
addEvent(doc, DOM_CONTENT_LOADED, function () {
isDomContentLoaded = true;
});
var SweetScroll = function () {

@@ -684,4 +689,6 @@

// Default options
babelHelpers.createClass(SweetScroll, [{

@@ -739,4 +746,4 @@ key: "to",

// Determine the final scroll coordinates
var frameSize = undefined;
var size = undefined;
var frameSize = void 0;
var size = void 0;
if (isRootContainer(container)) {

@@ -1028,3 +1035,3 @@ frameSize = { width: win.innerWidth, height: win.innerHeight };

var container = undefined;
var container = void 0;

@@ -1040,4 +1047,3 @@ if (verticalScroll) {

if (!container && !isDomContentLoaded) {
addEvent(doc, "DOMContentLoaded", function () {
isDomContentLoaded = true;
addEvent(doc, DOM_CONTENT_LOADED, function () {
_this3.getContainer(selector, callback);

@@ -1209,2 +1215,3 @@ });

SweetScroll.defaults = {

@@ -1211,0 +1218,0 @@ trigger: "[data-scroll]", // Selector for trigger (must be a valid css selector)

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

* @license MIT
* @version 0.3.0
* @version 0.3.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?it[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 i(n)&&n>=0&&et>=n}function r(e){return!n(e)&&"object"===t(e)}function i(n){return"number"===t(n)}function o(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 s(t){for(var n=arguments.length,e=Array(n>1?n-1:0),r=1;n>r;r++)e[r-1]=arguments[r];return c(e,function(n){c(n,function(n,e){t[e]=n})}),t}function c(t,n,i){if(null==t)return t;if(i=i||t,r(t)){for(var o in t)if(a(t,o)&&n.call(i,t[o],o)===!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 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 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),r=e.length;--r>=0&&e.item(r)!==t;);return r>-1}function g(t,n,e){var r=n.split(",");r.forEach(function(n){t.addEventListener(n.trim(),e,!1)})}function v(t,n,e){var r=n.split(",");r.forEach(function(n){t.removeEventListener(n.trim(),e,!1)})}function m(t){var n=document;return t===n.documentElement||t===n.body}function y(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],r=ot[n],i=t instanceof HTMLElement?[t]:p(t),o=[],l=document.createElement("div"),u=0;u<i.length;u++){var a=i[u];if(a[r]>0?o.push(a):(l.style.width=a.clientWidth+1+"px",l.style.height=a.clientHeight+1+"px",a.appendChild(l),a[r]=1,a[r]>0&&o.push(a),a[r]=0,a.removeChild(l)),!e&&o.length>0)break}return o}function S(t,n){var e=y(t,n,!1);return e.length>=1?e[0]:void 0}function C(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function k(t){var n=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],e=ot[n],r=lt[n],i=C(t);return i?i[r]:t[e]}function b(t,n){var e=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],r=ot[e],i=C(t),o="y"===e;i?i.scrollTo(o?i.pageXOffset:n,o?n:i.pageYOffset):t[r]=n}function w(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 r={},i=void 0;if(null==n||m(n))i=t.ownerDocument.documentElement,r.top=window.pageYOffset,r.left=window.pageXOffset;else{i=n;var o=i.getBoundingClientRect();r.top=-1*o.top+i.scrollTop,r.left=-1*o.left+i.scrollLeft}return{top:e.top+r.top-i.clientTop,left:e.left+r.left-i.clientLeft}}return e}function O(t){return t}function I(t,n,e,r,i){return r*(n/=i)*n+e}function x(t,n,e,r,i){return-r*(n/=i)*(n-2)+e}function L(t,n,e,r,i){return(n/=i/2)<1?r/2*n*n+e:-r/2*(--n*(n-2)-1)+e}function _(t,n,e,r,i){return r*(n/=i)*n*n+e}function E(t,n,e,r,i){return r*((n=n/i-1)*n*n+1)+e}function T(t,n,e,r,i){return(n/=i/2)<1?r/2*n*n*n+e:r/2*((n-=2)*n*n+2)+e}function M(t,n,e,r,i){return r*(n/=i)*n*n*n+e}function z(t,n,e,r,i){return-r*((n=n/i-1)*n*n*n-1)+e}function A(t,n,e,r,i){return(n/=i/2)<1?r/2*n*n*n*n+e:-r/2*((n-=2)*n*n*n-2)+e}function Q(t,n,e,r,i){return r*(n/=i)*n*n*n*n+e}function j(t,n,e,r,i){return r*((n=n/i-1)*n*n*n*n+1)+e}function B(t,n,e,r,i){return(n/=i/2)<1?r/2*n*n*n*n*n+e:r/2*((n-=2)*n*n*n*n+2)+e}function D(t,n,e,r,i){return-r*ct(n/i*(vt/2))+r+e}function H(t,n,e,r,i){return r*ft(n/i*(vt/2))+e}function q(t,n,e,r,i){return-r/2*(ct(vt*n/i)-1)+e}function P(t,n,e,r,i){return 0===n?e:r*ht(2,10*(n/i-1))+e}function F(t,n,e,r,i){return n===i?e+r:r*(-ht(2,-10*n/i)+1)+e}function R(t,n,e,r,i){return 0===n?e:n===i?e+r:(n/=i/2)<1?r/2*ht(2,10*(n-1))+e:r/2*(-ht(2,-10*--n)+2)+e}function W(t,n,e,r,i){return-r*(dt(1-(n/=i)*n)-1)+e}function $(t,n,e,r,i){return r*dt(1-(n=n/i-1)*n)+e}function N(t,n,e,r,i){return(n/=i/2)<1?-r/2*(dt(1-n*n)-1)+e:r/2*(dt(1-(n-=2)*n)+1)+e}function X(t,n,e,r,i){var o=1.70158,l=0,u=r;return 0===n?e:1===(n/=i)?e+r:(l||(l=.3*i),u<pt(r)?(u=r,o=l/4):o=l/(2*vt)*gt(r/u),-(u*ht(2,10*(n-=1))*ft((n*i-o)*(2*vt)/l))+e)}function Y(t,n,e,r,i){var o=1.70158,l=0,u=r;return 0===n?e:1===(n/=i)?e+r:(l||(l=.3*i),u<pt(r)?(u=r,o=l/4):o=l/(2*vt)*gt(r/u),u*ht(2,-10*n)*ft((n*i-o)*(2*vt)/l)+r+e)}function J(t,n,e,r,i){var o=1.70158,l=0,u=r;return 0===n?e:2===(n/=i/2)?e+r:(l||(l=i*(.3*1.5)),u<pt(r)?(u=r,o=l/4):o=l/(2*vt)*gt(r/u),1>n?-.5*(u*ht(2,10*(n-=1))*ft((n*i-o)*(2*vt)/l))+e:u*ht(2,-10*(n-=1))*ft((n*i-o)*(2*vt)/l)*.5+r+e)}function V(t,n,e,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*(n/=i)*n*((o+1)*n-o)+e}function G(t,n,e,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*((n=n/i-1)*n*((o+1)*n+o)+1)+e}function K(t,n,e,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(n/=i/2)<1?r/2*(n*n*(((o*=1.525)+1)*n-o))+e:r/2*((n-=2)*n*(((o*=1.525)+1)*n+o)+2)+e}function U(t,n,e,r,i){return r-Z(t,i-n,0,r,i)+e}function Z(t,n,e,r,i){return(n/=i)<1/2.75?r*(7.5625*n*n)+e:2/2.75>n?r*(7.5625*(n-=1.5/2.75)*n+.75)+e:2.5/2.75>n?r*(7.5625*(n-=2.25/2.75)*n+.9375)+e:r*(7.5625*(n-=2.625/2.75)*n+.984375)+e}function tt(t,n,e,r,i){return i/2>n?.5*U(t,2*n,0,r,i)+e:.5*Z(t,2*n-i,0,r,i)+.5*r+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 r=n[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(n,e,r){return e&&t(n.prototype,e),r&&t(n,r),n}}();var et=Math.pow(2,53)-1,rt=["Boolean","Number","String","Function","Array","Object"],it={};rt.forEach(function(t){it["[object "+t+"]"]=t.toLowerCase()});var ot={y:"scrollTop",x:"scrollLeft"},lt={y:"pageYOffset",x:"pageXOffset"},ut=0,at=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var n=Date.now(),e=Math.max(0,16-(n-ut)),r=window.setTimeout(function(){t(n+e)},e);return ut=n+e,r},st=Math,ct=st.cos,ft=st.sin,ht=st.pow,pt=st.abs,dt=st.sqrt,gt=st.asin,vt=st.PI,mt=Object.freeze({linear:O,InQuad:I,OutQuad:x,InOutQuad:L,InCubic:_,OutCubic:E,InOutCubic:T,InQuart:M,OutQuart:z,InOutQuart:A,InQuint:Q,OutQuint:j,InOutQuint:B,InSine:D,OutSine:H,InOutSine:q,InExpo:P,OutExpo:F,InOutExpo:R,InCirc:W,OutCirc:$,InOutCirc:N,InElastic:X,OutElastic:Y,InOutElastic:J,InBack:V,OutBack:G,InOutBack:K,InBounce:U,OutBounce:Z,InOutBounce:tt}),yt=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,r,i){var o=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=r,this.easing=i.replace("ease",""),this.callback=l,this.progress=!0,setTimeout(function(){o.startProps={x:k(o.el,"x"),y:k(o.el,"y")},at(function(t){return o._loop(t)})},r))}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!0:arguments[0];this.startTime=null,this.progress=!1,t&&(b(this.el,this.props.x,"x"),b(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,r=this.props,i=this.duration,o=this.startTime,l=this.startProps,u={},a=mt[this.easing],s=t-o,f=Math.min(1,Math.max(s/i,0));c(r,function(t,n){var e=l[n],r=t-e;if(0===r)return!0;var o=a(f,i*f,0,1,i);u[n]=Math.round(e+r*o)}),c(u,function(t,n){b(e,t,n)}),i>=s?at(function(t){return n._loop(t)}):this.stop(!0)}}]),t}(),St=window,Ct=document,kt="onwheel"in Ct?"wheel":"onmousewheel"in Ct?"mousewheel":"DOMMouseScroll",bt=kt+", touchstart, touchmove",wt=!1,Ot=function(){function t(){var n=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],r=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];nt.classCallCheck(this,t);var i=s({},t.defaults,e);this.options=i,this.getContainer(r,function(t){n.container=t,n.header=h(i.header),n.tween=new yt(t),n._trigger=null,n._shouldCallCancelScroll=!1,n.bindContainerClick(),n.initialized(),n.hook(i.initialized)})}return nt.createClass(t,[{key:"to",value:function(t){var n=this,e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this.container,i=this.header,l=s({},this.options,e),u=this.parseCoodinate(l.offset),a=this._trigger,c=this.parseCoodinate(t);if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),r){if(!c&&o(t))if("#"===t)c={top:0,left:0};else if(!/[:,]/.test(t)){var f=h(t),p=w(f,r);if(!p)return;c=p}if(c){u&&(c.top+=u.top,c.left+=u.left),i&&(c.top=Math.max(0,c.top-this.header.clientHeight));var d=void 0,g=void 0;m(r)?(d={width:St.innerWidth,height:St.innerHeight},g={width:Ct.body.scrollWidth,height:Ct.body.scrollHeight}):(d={width:r.clientWidth,height:r.clientHeight},g={width:r.scrollWidth,height:r.scrollHeight}),this.hook(l.beforeScroll,c,a)!==!1&&this.beforeScroll(c,a)!==!1&&(l.verticalScroll?c.top=Math.max(0,Math.min(g.height-d.height,c.top)):c.top=k(r,"y"),l.horizontalScroll?c.left=Math.max(0,Math.min(g.width-d.width,c.left)):c.left=k(r,"x"),this.tween.run(c.left,c.top,l.duration,l.delay,l.easing,function(){n.unbindContainerStop(),n._shouldCallCancelScroll?(n.hook(l.cancelScroll),n.cancelScroll()):(n.hook(l.afterScroll,c,a),n.afterScroll(c,a))}),this.bindContainerStop())}}}},{key:"toTop",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,s({},n,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof HTMLElement){var e=w(t,this.container);this.to(e,s({},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=s({},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:"parseCoodinate",value:function(t){var e=this.options.verticalScroll,r={top:0,left:0};if(a(t,"top")||a(t,"left"))r=s(r,t);else if(n(t))2===t.length?(r.top=t[0],r.left=t[1]):(r.top=e?t[0]:0,r.left=e?0:t[0]);else if(u(t))r.top=e?t:0,r.left=e?0:t;else{if(!o(t))return null;if(t=f(t),/^\d+,\d+$/.test(t))t=t.split(","),r.top=t[0],r.left=t[1];else if(/^(top|left):\d+,?(?:(top|left):\d+)?$/.test(t)){var i=t.match(/top:(\d+)/),l=t.match(/left:(\d+)/);r.top=i?i[1]:0,r.left=l?l[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(t))return null;var c=k(this.container,e?"y":"x"),h=t.match(/^(\+|-)\=(\d+)$/),p=h[1],d=parseInt(h[2],10);"+"===p?(r.top=e?c+d:0,r.left=e?0:c+d):(r.top=e?c-d:0,r.left=e?0:c-d)}}return r.top=parseInt(r.top,10),r.left=parseInt(r.left,10),r}},{key:"getContainer",value:function(t,n){var e=this,r=this.options,i=r.verticalScroll,o=r.horizontalScroll,l=void 0;i&&(l=S(t,"y")),!l&&o&&(l=S(t,"x")),l||wt?n.call(this,l):g(Ct,"DOMContentLoaded",function(){wt=!0,e.getContainer(t,n)})}},{key:"bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this.handleContainerClick.bind(this),g(t,"click",this._containerClickListener))}},{key:"unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(v(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this.handleStopScroll.bind(this),g(t,bt,this._stopScrollListener))}},{key:"unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(v(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),r=1;n>r;r++)e[r-1]=arguments[r];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!==Ct;e=e.parentNode)if(d(e,n.trigger)){var r=e.getAttribute("data-scroll"),i=this.parseDataOptions(e),o=r||e.getAttribute("href");n=s({},n,i),t.preventDefault(),t.stopPropagation(),this._trigger=e,n.horizontalScroll&&n.verticalScroll?this.to(o,n):n.verticalScroll?this.toTop(o,n):n.horizontalScroll&&this.toLeft(o,n)}}},{key:"parseDataOptions",value:function(t){var n=t.getAttribute("data-scroll-options");return n?JSON.parse(n):{}}}]),t}();return Ot.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null},Ot});
!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 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),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 HTMLElement?[t]:p(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 I(t,n,e,i,o){return i*(n/=o)*n+e}function x(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 T(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 z(t,n,e,i,o){return-i*((n=n/o-1)*n*n*n-1)+e}function A(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 Q(t,n,e,i,o){return i*(n/=o)*n*n*n*n+e}function j(t,n,e,i,o){return i*((n=n/o-1)*n*n*n*n+1)+e}function B(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 D(t,n,e,i,o){return-i*at(n/o*(dt/2))+i+e}function H(t,n,e,i,o){return i*ct(n/o*(dt/2))+e}function q(t,n,e,i,o){return-i/2*(at(dt*n/o)-1)+e}function P(t,n,e,i,o){return 0===n?e:i*st(2,10*(n/o-1))+e}function F(t,n,e,i,o){return n===o?e+i:i*(-st(2,-10*n/o)+1)+e}function R(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 W(t,n,e,i,o){return-i*(ht(1-(n/=o)*n)-1)+e}function $(t,n,e,i,o){return i*ht(1-(n=n/o-1)*n)+e}function N(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 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*dt)*pt(i/u),-(u*st(2,10*(n-=1))*ct((n*o-r)*(2*dt)/l))+e)}function Y(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*dt)*pt(i/u),u*st(2,-10*n)*ct((n*o-r)*(2*dt)/l)+i+e)}function J(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*dt)*pt(i/u),1>n?-.5*(u*st(2,10*(n-=1))*ct((n*o-r)*(2*dt)/l))+e:u*st(2,-10*(n-=1))*ct((n*o-r)*(2*dt)/l)*.5+i+e)}function V(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 G(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 K(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 U(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*U(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,pt=ut.asin,dt=ut.PI,vt=Object.freeze({linear:O,InQuad:I,OutQuad:x,InOutQuad:L,InCubic:_,OutCubic:E,InOutCubic:T,InQuart:M,OutQuart:z,InOutQuart:A,InQuint:Q,OutQuint:j,InOutQuint:B,InSine:D,OutSine:H,InOutSine:q,InExpo:P,OutExpo:F,InOutExpo:R,InCirc:W,OutCirc:$,InOutCirc:N,InElastic:X,OutElastic:Y,InOutElastic:J,InBack:V,OutBack:G,InOutBack:K,InBounce:U,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 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);if(this._trigger=null,this._shouldCallCancelScroll=!1,this.stop(),i){if(!s&&r(t))if("#"===t)s={top:0,left:0};else if(!/[:,]/.test(t)){var f=h(t),p=k(f,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 d=void 0,g=void 0;v(i)?(d={width:Ct.innerWidth,height:Ct.innerHeight},g={width:mt.body.scrollWidth,height:mt.body.scrollHeight}):(d={width:i.clientWidth,height:i.clientHeight},g={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(g.height-d.height,s.top)):s.top=C(i,"y"),l.horizontalScroll?s.left=Math.max(0,Math.min(g.width-d.width,s.left)):s.left=C(i,"x"),this.tween.run(s.left,s.top,l.duration,l.delay,l.easing,function(){n.unbindContainerStop(),n._shouldCallCancelScroll?(n.hook(l.cancelScroll),n.cancelScroll()):(n.hook(l.afterScroll,s,a),n.afterScroll(s,a))}),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 HTMLElement){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:"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+)$/),p=h[1],d=parseInt(h[2],10);"+"===p?(i.top=e?s+d:0,i.left=e?0:s+d):(i.top=e?s-d:0,i.left=e?0:s-d)}}return i.top=parseInt(i.top,10),i.left=parseInt(i.left,10),i}},{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(d(e,n.trigger)){var i=e.getAttribute("data-scroll"),o=this.parseDataOptions(e),r=i||e.getAttribute("href");n=c({},n,o),t.preventDefault(),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,initialized:null,beforeScroll:null,afterScroll:null,cancelScroll:null},It});
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