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.2.0 to 0.2.1

2

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

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

@@ -10,11 +10,12 @@ sweet-scroll.js

Modern and the sweet smooth scroll library.
ECMAScript2015 Friendly, dependency-free smooth scroll library.
[View Demo](http://tsuyoshiwada.github.io/sweet-scroll/)
[See Demo](http://tsuyoshiwada.github.io/sweet-scroll/)
## FEATURES
* Dependecy-free!!
* ECMAScript 2015(ES6) frendly
* ECMAScript2015 friendly
* Use `requestAnimationFrame` API (IE9 works in `setTimeout` instead)

@@ -26,2 +27,4 @@ * Supports vertical and horizontal scroll

## USAGE

@@ -28,0 +31,0 @@

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

* @license MIT
* @version 0.2.0
* @version 0.2.1
*/

@@ -659,4 +659,6 @@ (function (global, factory) {

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

@@ -669,2 +671,3 @@ key: "to",

var container = this.container;
var header = this.header;

@@ -706,4 +709,4 @@ var params = merge({}, this.options, options);

// If the header is present apply the height
if (this.header) {
scroll.top = Math.max(0, scroll.top - this.header.clientHeight);
if (header) {
scroll.top = Math.max(0, scroll.top - (header.clientHeight + header.getBoundingClientRect().top));
}

@@ -1120,2 +1123,3 @@

SweetScroll.defaults = {

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

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

* @license MIT
* @version 0.2.0
* @version 0.2.1
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.SweetScroll=e()}(this,function(){"use strict";function t(t){return null==t?t+"":"object"===("undefined"==typeof t?"undefined":et["typeof"](t))||"function"==typeof t?it[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":et["typeof"](t)}function e(t){return Array.isArray(t)}function n(t){var e=null==t?null:t.length;return i(e)&&e>=0&&nt>=e}function r(n){return!e(n)&&"object"===t(n)}function i(e){return"number"===t(e)}function o(e){return"string"===t(e)}function a(e){return"function"===t(e)}function u(t){return!e(t)&&t-parseFloat(t)+1>=0}function s(t,e){return t&&Object.prototype.hasOwnProperty.call(t,e)}function l(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return c(n,function(e){c(e,function(e,n){t[n]=e})}),t}function c(t,e,i){if(null==t)return t;if(i=i||t,r(t)){for(var o in t)if(s(t,o)&&e.call(i,t[o],o)===!1)break}else if(n(t)){var a=void 0,u=t.length;for(a=0;u>a&&e.call(i,t[a],a)!==!1;a++);}return t}function h(t){return t.replace(/\s*/g,"")||""}function f(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelector(t)}function p(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelectorAll(t)}function g(t,e){for(var n=(t.document||t.ownerDocument).querySelectorAll(e),r=n.length;--r>=0&&n.item(r)!==t;);return r>-1}function d(t){var e=document;return t===e.documentElement||t===e.body}function m(t){for(var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],r=ot[e],i=t instanceof HTMLElement?[t]:p(t),o=[],a=document.createElement("div"),u=0;u<i.length;u++){var s=i[u];if(s[r]>0?o.push(s):(a.style.width=s.clientWidth+1+"px",a.style.height=s.clientHeight+1+"px",s.appendChild(a),s[r]=1,s[r]>0&&o.push(s),s[r]=0,s.removeChild(a)),!n&&o.length>0)break}return o}function v(t,e){var n=m(t,e,!1);return n.length>=1?n[0]:void 0}function y(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function S(t){var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=ot[e],r=at[e],i=y(t);return i?i[r]:t[n]}function b(t,e){var n=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],r=ot[n],i=y(t),o="y"===n;i?i.scrollTo(o?i.pageXOffset:e,o?e:i.pageYOffset):t[r]=e}function C(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var n=t.getBoundingClientRect();if(n.width||n.height){var r={},i=void 0;if(null==e||d(e))i=t.ownerDocument.documentElement,r.top=window.pageYOffset,r.left=window.pageXOffset;else{i=e;var o=i.getBoundingClientRect();r.top=-1*o.top+i.scrollTop,r.left=-1*o.left+i.scrollLeft}return{top:n.top+r.top-i.clientTop,left:n.left+r.left-i.clientLeft}}return n}function k(t,e,n){t.addEventListener(e,n,!1)}function _(t,e,n){t.removeEventListener(e,n,!1)}function w(t){return t}function O(t,e,n,r,i){return r*(e/=i)*e+n}function I(t,e,n,r,i){return-r*(e/=i)*(e-2)+n}function L(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e+n:-r/2*(--e*(e-2)-1)+n}function x(t,e,n,r,i){return r*(e/=i)*e*e+n}function M(t,e,n,r,i){return r*((e=e/i-1)*e*e+1)+n}function T(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e+n:r/2*((e-=2)*e*e+2)+n}function E(t,e,n,r,i){return r*(e/=i)*e*e*e+n}function A(t,e,n,r,i){return-r*((e=e/i-1)*e*e*e-1)+n}function j(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e+n:-r/2*((e-=2)*e*e*e-2)+n}function Q(t,e,n,r,i){return r*(e/=i)*e*e*e*e+n}function z(t,e,n,r,i){return r*((e=e/i-1)*e*e*e*e+1)+n}function B(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e*e+n:r/2*((e-=2)*e*e*e*e+2)+n}function D(t,e,n,r,i){return-r*lt(e/i*(dt/2))+r+n}function H(t,e,n,r,i){return r*ct(e/i*(dt/2))+n}function q(t,e,n,r,i){return-r/2*(lt(dt*e/i)-1)+n}function P(t,e,n,r,i){return 0===e?n:r*ht(2,10*(e/i-1))+n}function F(t,e,n,r,i){return e===i?n+r:r*(-ht(2,-10*e/i)+1)+n}function R(t,e,n,r,i){return 0===e?n:e===i?n+r:(e/=i/2)<1?r/2*ht(2,10*(e-1))+n:r/2*(-ht(2,-10*--e)+2)+n}function W(t,e,n,r,i){return-r*(pt(1-(e/=i)*e)-1)+n}function $(t,e,n,r,i){return r*pt(1-(e=e/i-1)*e)+n}function N(t,e,n,r,i){return(e/=i/2)<1?-r/2*(pt(1-e*e)-1)+n:r/2*(pt(1-(e-=2)*e)+1)+n}function X(t,e,n,r,i){var o=1.70158,a=0,u=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),u<ft(r)?(u=r,o=a/4):o=a/(2*dt)*gt(r/u),-(u*ht(2,10*(e-=1))*ct((e*i-o)*(2*dt)/a))+n)}function Y(t,e,n,r,i){var o=1.70158,a=0,u=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),u<ft(r)?(u=r,o=a/4):o=a/(2*dt)*gt(r/u),u*ht(2,-10*e)*ct((e*i-o)*(2*dt)/a)+r+n)}function J(t,e,n,r,i){var o=1.70158,a=0,u=r;return 0===e?n:2===(e/=i/2)?n+r:(a||(a=i*(.3*1.5)),u<ft(r)?(u=r,o=a/4):o=a/(2*dt)*gt(r/u),1>e?-.5*(u*ht(2,10*(e-=1))*ct((e*i-o)*(2*dt)/a))+n:u*ht(2,-10*(e-=1))*ct((e*i-o)*(2*dt)/a)*.5+r+n)}function V(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*(e/=i)*e*((o+1)*e-o)+n}function G(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*((e=e/i-1)*e*((o+1)*e+o)+1)+n}function K(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(e/=i/2)<1?r/2*(e*e*(((o*=1.525)+1)*e-o))+n:r/2*((e-=2)*e*(((o*=1.525)+1)*e+o)+2)+n}function U(t,e,n,r,i){return r-Z(t,i-e,0,r,i)+n}function Z(t,e,n,r,i){return(e/=i)<1/2.75?r*(7.5625*e*e)+n:2/2.75>e?r*(7.5625*(e-=1.5/2.75)*e+.75)+n:2.5/2.75>e?r*(7.5625*(e-=2.25/2.75)*e+.9375)+n:r*(7.5625*(e-=2.625/2.75)*e+.984375)+n}function tt(t,e,n,r,i){return i/2>e?.5*U(t,2*e,0,r,i)+n:.5*Z(t,2*e-i,0,r,i)+.5*r+n}var et={};et["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},et.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},et.createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();var nt=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"},at={y:"pageYOffset",x:"pageXOffset"},ut=0,st=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var e=Date.now(),n=Math.max(0,16-(e-ut)),r=window.setTimeout(function(){t(e+n)},n);return ut=e+n,r},lt=Math.cos,ct=Math.sin,ht=Math.pow,ft=Math.abs,pt=Math.sqrt,gt=Math.asin,dt=Math.PI,mt=Object.freeze({linear:w,easeInQuad:O,easeOutQuad:I,easeInOutQuad:L,easeInCubic:x,easeOutCubic:M,easeInOutCubic:T,easeInQuart:E,easeOutQuart:A,easeInOutQuart:j,easeInQuint:Q,easeOutQuint:z,easeInOutQuint:B,easeInSine:D,easeOutSine:H,easeInOutSine:q,easeInExpo:P,easeOutExpo:F,easeInOutExpo:R,easeInCirc:W,easeOutCirc:$,easeInOutCirc:N,easeInElastic:X,easeOutElastic:Y,easeInOutElastic:J,easeInBack:V,easeOutBack:G,easeInOutBack:K,easeInBounce:U,easeOutBounce:Z,easeInOutBounce:tt}),vt=function(){function t(e){et.classCallCheck(this,t),this.el=e,this.props={},this.progress=!1,this.startTime=null}return et.createClass(t,[{key:"run",value:function(t,e,n,r,i){var o=this,a=arguments.length<=5||void 0===arguments[5]?function(){}:arguments[5];this.progress||(this.props={x:t,y:e},this.duration=n,this.delay=r,this.easing=i,this.callback=a,this.progress=!0,setTimeout(function(){o.startProps={x:S(o.el,"x"),y:S(o.el,"y")},st(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")),a(this.callback)&&(this.callback(),this.callback=null)}},{key:"_loop",value:function(t){var e=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var n=this.el,r=this.props,i=this.duration,o=this.startTime,a=this.startProps,u={},s=mt[this.easing],l=t-o,h=Math.min(1,Math.max(l/i,0));c(r,function(t,e){var n=a[e],r=t-n;if(0===r)return!0;var o=s(h,i*h,0,1,i);u[e]=Math.round(n+r*o)}),c(u,function(t,e){b(n,t,e)}),i>=l?st(function(t){return e._loop(t)}):this.stop(!0)}}]),t}(),yt=window,St=document,bt="onwheel"in St?"wheel":"onmousewheel"in St?"mousewheel":"DOMMouseScroll",Ct=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];et.classCallCheck(this,t),this.options=l({},t.defaults,e),this.container=this._getContainer(n),this.header=f(this.options.header),this.tween=new vt(this.container),this._trigger=null,this._bindContainerClick()}return et.createClass(t,[{key:"to",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this.container,i=l({},this.options,n),a=this._parseCoodinate(i.offset),u=this._trigger,s=this._parseCoodinate(t);if(this._trigger=null,this.stop(),r){if(!s&&o(t))if("#"===t)s={top:0,left:0};else if(!/[:,]/.test(t)){var c=f(t),h=C(c,r);if(!h)return;s=h}if(s){a&&(s.top+=a.top,s.left+=a.left),this.header&&(s.top=Math.max(0,s.top-this.header.clientHeight));var p=void 0,g=void 0;d(r)?(p={width:yt.innerWidth,height:yt.innerHeight},g={width:St.body.scrollWidth,height:St.body.scrollHeight}):(p={width:r.clientWidth,height:r.clientHeight},g={width:r.scrollWidth,height:r.scrollHeight}),i.verticalScroll?s.top=Math.max(0,Math.min(g.height-p.height,s.top)):s.top=S(r,"y"),i.horizontalScroll?s.left=Math.max(0,Math.min(g.width-p.width,s.left)):s.left=S(r,"x"),this._hook(i.beforeScroll,s,u)!==!1&&(this.tween.run(s.left,s.top,i.duration,i.delay,i.easing,function(){e._unbindContainerStop(),e._hook(i.afterScroll,s,u)}),this._bindContainerStop())}}}},{key:"toTop",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof HTMLElement){var n=C(t,this.container);this.to(n,l({},e))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[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=l({},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:"_getContainer",value:function(t){var e=this.options,n=e.verticalScroll,r=e.horizontalScroll,i=void 0;return n&&(i=v(t,"y")),!i&&r&&(i=v(t,"x")),i}},{key:"_bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this._handleContainerClick.bind(this),k(t,"click",this._containerClickListener))}},{key:"_unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(_(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"_bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this._handleStopScroll.bind(this),k(t,bt,this._stopScrollListener),k(t,"touchstart",this._stopScrollListener),k(t,"touchmove",this._stopScrollListener))}},{key:"_unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(_(t,bt,this._stopScrollListener),_(t,"touchstart",this._stopScrollListener),_(t,"touchmove",this._stopScrollListener),this._stopScrollListener=null)}},{key:"_hook",value:function(t){if(a(t)){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t.apply(this,n)}}},{key:"_parseCoodinate",value:function(t){var n=this.options.verticalScroll,r={top:0,left:0};if(s(t,"top")||s(t,"left"))r=l(r,t);else if(e(t))2===t.length?(r.top=t[0],r.left=t[1]):(r.top=n?t[0]:0,r.left=n?0:t[0]);else if(u(t))r.top=n?t:0,r.left=n?0:t;else{if(!o(t))return null;if(t=h(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+)/),a=t.match(/left:(\d+)/);r.top=i?i[1]:0,r.left=a?a[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(t))return null;var c=S(this.container,n?"y":"x"),f=t.match(/^(\+|-)\=(\d+)$/),p=f[1],g=parseInt(f[2],10);"+"===p?(r.top=n?c+g:0,r.left=n?0:c+g):(r.top=n?c-g:0,r.left=n?0:c-g)}}return r.top=parseInt(r.top,10),r.left=parseInt(r.left,10),r}},{key:"_handleStopScroll",value:function(t){this.options.stopScroll?this._hook(this.options.cancelScroll)!==!1&&this.stop():t.preventDefault()}},{key:"_handleContainerClick",value:function(t){for(var e=this.options,n=t.target;n&&n!==St;n=n.parentNode)if(g(n,e.trigger)){var r=n.getAttribute("data-scroll"),i=this._parseDataOptions(n),o=r||n.getAttribute("href");e=l({},e,i),t.preventDefault(),t.stopPropagation(),this._trigger=n,e.horizontalScroll&&e.verticalScroll?this.to(o,e):e.verticalScroll?this.toTop(o,e):e.horizontalScroll&&this.toLeft(o,e)}}},{key:"_parseDataOptions",value:function(t){var e=t.getAttribute("data-scroll-options");return e?JSON.parse(e):{}}}]),t}();return Ct.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,beforeScroll:null,afterScroll:null,cancelScroll:null},Ct});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.SweetScroll=e()}(this,function(){"use strict";function t(t){return null==t?t+"":"object"===("undefined"==typeof t?"undefined":et["typeof"](t))||"function"==typeof t?it[Object.prototype.toString.call(t)]||"object":"undefined"==typeof t?"undefined":et["typeof"](t)}function e(t){return Array.isArray(t)}function n(t){var e=null==t?null:t.length;return i(e)&&e>=0&&nt>=e}function r(n){return!e(n)&&"object"===t(n)}function i(e){return"number"===t(e)}function o(e){return"string"===t(e)}function a(e){return"function"===t(e)}function u(t){return!e(t)&&t-parseFloat(t)+1>=0}function s(t,e){return t&&Object.prototype.hasOwnProperty.call(t,e)}function l(t){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return c(n,function(e){c(e,function(e,n){t[n]=e})}),t}function c(t,e,i){if(null==t)return t;if(i=i||t,r(t)){for(var o in t)if(s(t,o)&&e.call(i,t[o],o)===!1)break}else if(n(t)){var a=void 0,u=t.length;for(a=0;u>a&&e.call(i,t[a],a)!==!1;a++);}return t}function h(t){return t.replace(/\s*/g,"")||""}function f(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelector(t)}function p(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(t)return(null==e?document:e).querySelectorAll(t)}function g(t,e){for(var n=(t.document||t.ownerDocument).querySelectorAll(e),r=n.length;--r>=0&&n.item(r)!==t;);return r>-1}function d(t){var e=document;return t===e.documentElement||t===e.body}function m(t){for(var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=arguments.length<=2||void 0===arguments[2]?!0:arguments[2],r=ot[e],i=t instanceof HTMLElement?[t]:p(t),o=[],a=document.createElement("div"),u=0;u<i.length;u++){var s=i[u];if(s[r]>0?o.push(s):(a.style.width=s.clientWidth+1+"px",a.style.height=s.clientHeight+1+"px",s.appendChild(a),s[r]=1,s[r]>0&&o.push(s),s[r]=0,s.removeChild(a)),!n&&o.length>0)break}return o}function v(t,e){var n=m(t,e,!1);return n.length>=1?n[0]:void 0}function y(t){return null!=t&&t===t.window?t:9===t.nodeType&&t.defaultView}function S(t){var e=arguments.length<=1||void 0===arguments[1]?"y":arguments[1],n=ot[e],r=at[e],i=y(t);return i?i[r]:t[n]}function b(t,e){var n=arguments.length<=2||void 0===arguments[2]?"y":arguments[2],r=ot[n],i=y(t),o="y"===n;i?i.scrollTo(o?i.pageXOffset:e,o?e:i.pageYOffset):t[r]=e}function C(t){var e=arguments.length<=1||void 0===arguments[1]?null:arguments[1];if(!t||t&&!t.getClientRects().length)return{top:0,left:0};var n=t.getBoundingClientRect();if(n.width||n.height){var r={},i=void 0;if(null==e||d(e))i=t.ownerDocument.documentElement,r.top=window.pageYOffset,r.left=window.pageXOffset;else{i=e;var o=i.getBoundingClientRect();r.top=-1*o.top+i.scrollTop,r.left=-1*o.left+i.scrollLeft}return{top:n.top+r.top-i.clientTop,left:n.left+r.left-i.clientLeft}}return n}function k(t,e,n){t.addEventListener(e,n,!1)}function _(t,e,n){t.removeEventListener(e,n,!1)}function w(t){return t}function O(t,e,n,r,i){return r*(e/=i)*e+n}function I(t,e,n,r,i){return-r*(e/=i)*(e-2)+n}function L(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e+n:-r/2*(--e*(e-2)-1)+n}function x(t,e,n,r,i){return r*(e/=i)*e*e+n}function M(t,e,n,r,i){return r*((e=e/i-1)*e*e+1)+n}function T(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e+n:r/2*((e-=2)*e*e+2)+n}function E(t,e,n,r,i){return r*(e/=i)*e*e*e+n}function A(t,e,n,r,i){return-r*((e=e/i-1)*e*e*e-1)+n}function j(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e+n:-r/2*((e-=2)*e*e*e-2)+n}function B(t,e,n,r,i){return r*(e/=i)*e*e*e*e+n}function Q(t,e,n,r,i){return r*((e=e/i-1)*e*e*e*e+1)+n}function z(t,e,n,r,i){return(e/=i/2)<1?r/2*e*e*e*e*e+n:r/2*((e-=2)*e*e*e*e+2)+n}function D(t,e,n,r,i){return-r*lt(e/i*(dt/2))+r+n}function H(t,e,n,r,i){return r*ct(e/i*(dt/2))+n}function q(t,e,n,r,i){return-r/2*(lt(dt*e/i)-1)+n}function P(t,e,n,r,i){return 0===e?n:r*ht(2,10*(e/i-1))+n}function R(t,e,n,r,i){return e===i?n+r:r*(-ht(2,-10*e/i)+1)+n}function F(t,e,n,r,i){return 0===e?n:e===i?n+r:(e/=i/2)<1?r/2*ht(2,10*(e-1))+n:r/2*(-ht(2,-10*--e)+2)+n}function W(t,e,n,r,i){return-r*(pt(1-(e/=i)*e)-1)+n}function $(t,e,n,r,i){return r*pt(1-(e=e/i-1)*e)+n}function N(t,e,n,r,i){return(e/=i/2)<1?-r/2*(pt(1-e*e)-1)+n:r/2*(pt(1-(e-=2)*e)+1)+n}function X(t,e,n,r,i){var o=1.70158,a=0,u=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),u<ft(r)?(u=r,o=a/4):o=a/(2*dt)*gt(r/u),-(u*ht(2,10*(e-=1))*ct((e*i-o)*(2*dt)/a))+n)}function Y(t,e,n,r,i){var o=1.70158,a=0,u=r;return 0===e?n:1===(e/=i)?n+r:(a||(a=.3*i),u<ft(r)?(u=r,o=a/4):o=a/(2*dt)*gt(r/u),u*ht(2,-10*e)*ct((e*i-o)*(2*dt)/a)+r+n)}function J(t,e,n,r,i){var o=1.70158,a=0,u=r;return 0===e?n:2===(e/=i/2)?n+r:(a||(a=i*(.3*1.5)),u<ft(r)?(u=r,o=a/4):o=a/(2*dt)*gt(r/u),1>e?-.5*(u*ht(2,10*(e-=1))*ct((e*i-o)*(2*dt)/a))+n:u*ht(2,-10*(e-=1))*ct((e*i-o)*(2*dt)/a)*.5+r+n)}function V(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*(e/=i)*e*((o+1)*e-o)+n}function G(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return r*((e=e/i-1)*e*((o+1)*e+o)+1)+n}function K(t,e,n,r,i){var o=arguments.length<=5||void 0===arguments[5]?1.70158:arguments[5];return(e/=i/2)<1?r/2*(e*e*(((o*=1.525)+1)*e-o))+n:r/2*((e-=2)*e*(((o*=1.525)+1)*e+o)+2)+n}function U(t,e,n,r,i){return r-Z(t,i-e,0,r,i)+n}function Z(t,e,n,r,i){return(e/=i)<1/2.75?r*(7.5625*e*e)+n:2/2.75>e?r*(7.5625*(e-=1.5/2.75)*e+.75)+n:2.5/2.75>e?r*(7.5625*(e-=2.25/2.75)*e+.9375)+n:r*(7.5625*(e-=2.625/2.75)*e+.984375)+n}function tt(t,e,n,r,i){return i/2>e?.5*U(t,2*e,0,r,i)+n:.5*Z(t,2*e-i,0,r,i)+.5*r+n}var et={};et["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},et.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},et.createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,n,r){return n&&t(e.prototype,n),r&&t(e,r),e}}();var nt=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"},at={y:"pageYOffset",x:"pageXOffset"},ut=0,st=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){var e=Date.now(),n=Math.max(0,16-(e-ut)),r=window.setTimeout(function(){t(e+n)},n);return ut=e+n,r},lt=Math.cos,ct=Math.sin,ht=Math.pow,ft=Math.abs,pt=Math.sqrt,gt=Math.asin,dt=Math.PI,mt=Object.freeze({linear:w,easeInQuad:O,easeOutQuad:I,easeInOutQuad:L,easeInCubic:x,easeOutCubic:M,easeInOutCubic:T,easeInQuart:E,easeOutQuart:A,easeInOutQuart:j,easeInQuint:B,easeOutQuint:Q,easeInOutQuint:z,easeInSine:D,easeOutSine:H,easeInOutSine:q,easeInExpo:P,easeOutExpo:R,easeInOutExpo:F,easeInCirc:W,easeOutCirc:$,easeInOutCirc:N,easeInElastic:X,easeOutElastic:Y,easeInOutElastic:J,easeInBack:V,easeOutBack:G,easeInOutBack:K,easeInBounce:U,easeOutBounce:Z,easeInOutBounce:tt}),vt=function(){function t(e){et.classCallCheck(this,t),this.el=e,this.props={},this.progress=!1,this.startTime=null}return et.createClass(t,[{key:"run",value:function(t,e,n,r,i){var o=this,a=arguments.length<=5||void 0===arguments[5]?function(){}:arguments[5];this.progress||(this.props={x:t,y:e},this.duration=n,this.delay=r,this.easing=i,this.callback=a,this.progress=!0,setTimeout(function(){o.startProps={x:S(o.el,"x"),y:S(o.el,"y")},st(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")),a(this.callback)&&(this.callback(),this.callback=null)}},{key:"_loop",value:function(t){var e=this;if(this.startTime||(this.startTime=t),!this.progress)return void this.stop(!1);var n=this.el,r=this.props,i=this.duration,o=this.startTime,a=this.startProps,u={},s=mt[this.easing],l=t-o,h=Math.min(1,Math.max(l/i,0));c(r,function(t,e){var n=a[e],r=t-n;if(0===r)return!0;var o=s(h,i*h,0,1,i);u[e]=Math.round(n+r*o)}),c(u,function(t,e){b(n,t,e)}),i>=l?st(function(t){return e._loop(t)}):this.stop(!0)}}]),t}(),yt=window,St=document,bt="onwheel"in St?"wheel":"onmousewheel"in St?"mousewheel":"DOMMouseScroll",Ct=function(){function t(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments.length<=1||void 0===arguments[1]?"body, html":arguments[1];et.classCallCheck(this,t),this.options=l({},t.defaults,e),this.container=this._getContainer(n),this.header=f(this.options.header),this.tween=new vt(this.container),this._trigger=null,this._bindContainerClick()}return et.createClass(t,[{key:"to",value:function(t){var e=this,n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=this.container,i=this.header,a=l({},this.options,n),u=this._parseCoodinate(a.offset),s=this._trigger,c=this._parseCoodinate(t);if(this._trigger=null,this.stop(),r){if(!c&&o(t))if("#"===t)c={top:0,left:0};else if(!/[:,]/.test(t)){var h=f(t),p=C(h,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-(i.clientHeight+i.getBoundingClientRect().top)));var g=void 0,m=void 0;d(r)?(g={width:yt.innerWidth,height:yt.innerHeight},m={width:St.body.scrollWidth,height:St.body.scrollHeight}):(g={width:r.clientWidth,height:r.clientHeight},m={width:r.scrollWidth,height:r.scrollHeight}),a.verticalScroll?c.top=Math.max(0,Math.min(m.height-g.height,c.top)):c.top=S(r,"y"),a.horizontalScroll?c.left=Math.max(0,Math.min(m.width-g.width,c.left)):c.left=S(r,"x"),this._hook(a.beforeScroll,c,s)!==!1&&(this.tween.run(c.left,c.top,a.duration,a.delay,a.easing,function(){e._unbindContainerStop(),e._hook(a.afterScroll,c,s)}),this._bindContainerStop())}}}},{key:"toTop",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!0,horizontalScroll:!1}))}},{key:"toLeft",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];this.to(t,l({},e,{verticalScroll:!1,horizontalScroll:!0}))}},{key:"toElement",value:function(t){var e=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];if(t instanceof HTMLElement){var n=C(t,this.container);this.to(n,l({},e))}}},{key:"stop",value:function(){var t=arguments.length<=0||void 0===arguments[0]?!1:arguments[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=l({},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:"_getContainer",value:function(t){var e=this.options,n=e.verticalScroll,r=e.horizontalScroll,i=void 0;return n&&(i=v(t,"y")),!i&&r&&(i=v(t,"x")),i}},{key:"_bindContainerClick",value:function(){var t=this.container;t&&(this._containerClickListener=this._handleContainerClick.bind(this),k(t,"click",this._containerClickListener))}},{key:"_unbindContainerClick",value:function(){var t=this.container;t&&this._containerClickListener&&(_(t,"click",this._containerClickListener),this._containerClickListener=null)}},{key:"_bindContainerStop",value:function(){var t=this.container;t&&(this._stopScrollListener=this._handleStopScroll.bind(this),k(t,bt,this._stopScrollListener),k(t,"touchstart",this._stopScrollListener),k(t,"touchmove",this._stopScrollListener))}},{key:"_unbindContainerStop",value:function(){var t=this.container;t&&this._stopScrollListener&&(_(t,bt,this._stopScrollListener),_(t,"touchstart",this._stopScrollListener),_(t,"touchmove",this._stopScrollListener),this._stopScrollListener=null)}},{key:"_hook",value:function(t){if(a(t)){for(var e=arguments.length,n=Array(e>1?e-1:0),r=1;e>r;r++)n[r-1]=arguments[r];return t.apply(this,n)}}},{key:"_parseCoodinate",value:function(t){var n=this.options.verticalScroll,r={top:0,left:0};if(s(t,"top")||s(t,"left"))r=l(r,t);else if(e(t))2===t.length?(r.top=t[0],r.left=t[1]):(r.top=n?t[0]:0,r.left=n?0:t[0]);else if(u(t))r.top=n?t:0,r.left=n?0:t;else{if(!o(t))return null;if(t=h(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+)/),a=t.match(/left:(\d+)/);r.top=i?i[1]:0,r.left=a?a[1]:0}else{if(!this.container||!/^(\+|-)=(\d+)$/.test(t))return null;var c=S(this.container,n?"y":"x"),f=t.match(/^(\+|-)\=(\d+)$/),p=f[1],g=parseInt(f[2],10);"+"===p?(r.top=n?c+g:0,r.left=n?0:c+g):(r.top=n?c-g:0,r.left=n?0:c-g)}}return r.top=parseInt(r.top,10),r.left=parseInt(r.left,10),r}},{key:"_handleStopScroll",value:function(t){this.options.stopScroll?this._hook(this.options.cancelScroll)!==!1&&this.stop():t.preventDefault()}},{key:"_handleContainerClick",value:function(t){for(var e=this.options,n=t.target;n&&n!==St;n=n.parentNode)if(g(n,e.trigger)){var r=n.getAttribute("data-scroll"),i=this._parseDataOptions(n),o=r||n.getAttribute("href");e=l({},e,i),t.preventDefault(),t.stopPropagation(),this._trigger=n,e.horizontalScroll&&e.verticalScroll?this.to(o,e):e.verticalScroll?this.toTop(o,e):e.horizontalScroll&&this.toLeft(o,e)}}},{key:"_parseDataOptions",value:function(t){var e=t.getAttribute("data-scroll-options");return e?JSON.parse(e):{}}}]),t}();return Ct.defaults={trigger:"[data-scroll]",header:"[data-scroll-header]",duration:1e3,delay:0,easing:"easeOutQuint",offset:0,verticalScroll:!0,horizontalScroll:!1,stopScroll:!0,beforeScroll:null,afterScroll:null,cancelScroll:null},Ct});
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