diff --git a/dist/scrolltosmooth.cjs.js b/dist/scrolltosmooth.cjs.js index b85b5ba..1d88229 100644 --- a/dist/scrolltosmooth.cjs.js +++ b/dist/scrolltosmooth.cjs.js @@ -1,7 +1,7 @@ /*! * ScrollToSmooth * Author: Bastian Fießinger -* Version: 3.0.0 +* Version: 3.0.1 */ 'use strict'; diff --git a/dist/scrolltosmooth.esm.js b/dist/scrolltosmooth.esm.js index b5a53d9..8617c2f 100644 --- a/dist/scrolltosmooth.esm.js +++ b/dist/scrolltosmooth.esm.js @@ -1,7 +1,7 @@ /*! * ScrollToSmooth * Author: Bastian Fießinger -* Version: 3.0.0 +* Version: 3.0.1 */ function _typeof(obj) { "@babel/helpers - typeof"; diff --git a/dist/scrolltosmooth.min.js b/dist/scrolltosmooth.min.js index 5742146..f93d156 100644 --- a/dist/scrolltosmooth.min.js +++ b/dist/scrolltosmooth.min.js @@ -1,6 +1,6 @@ /*! * ScrollToSmooth * Author: Bastian Fießinger -* Version: 3.0.0 +* Version: 3.0.1 */ var scrollToSmooth=function(){"use strict";function t(n){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(n)}function n(t,n){for(var e=0;et.length)&&(n=t.length);for(var e=0,i=new Array(n);e1&&void 0!==arguments[1]?arguments[1]:s;return n.querySelector(t)},g=function(t,n){Array.prototype.forEach.call(t,n)},p=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:s,e=!0;try{"string"==typeof t?h(t,n):y(t)&&n.contains(t)}catch(t){e=!1}return e},y=function(n){return function(n){try{return n instanceof Node}catch(e){return"object"===t(n)&&"number"==typeof n.nodeType&&"string"==typeof n.nodeName&&"object"===t(n.ownerDocument)}}(n)||function(n){try{return n instanceof HTMLElement}catch(e){return"object"===t(n)&&1===n.nodeType&&"object"===t(n.style)&&"object"===t(n.ownerDocument)}}(n)},d=function(){return l.pageYOffset||c.scrollTop||a.scrollTop},m=function(){return l.performance&&"now"in l.performance?performance.now():(new Date).getTime()},v=function(t){var n=new RegExp("("+location.hash+")?$");return(t.baseURI||s.URL).replace(n,"")},b=function(){return Math.max(c.scrollHeight,c.offsetHeight,c.clientHeight,a.scrollHeight,a.offsetHeight,a.clientHeight)},S=function(){return l.innerHeight||a.clientHeight||c.clientHeight},A=function(t){return t+"px"},w="data-scrolltosmooth-expand",E="top",x="bottom";function j(t){var n="";return"href"===this.settings.targetAttribute&&t.href?n=t.href.replace(v(t),""):t.getAttribute(this.settings.targetAttribute)&&(n=t.getAttribute(this.settings.targetAttribute)),this.settings.topOnEmptyHash&&"#"==n?this.container:(console.log(n,p(n,this.container)),p(n,this.container)?h(n,this.container):null)}function O(){var t=this,n=[];return g(this.elements,(function(e){j.call(t,e)&&("href"===t.settings.targetAttribute&&-1!=e.href.indexOf(v(e))&&-1!=e.href.indexOf("#")&&(""!=e.hash||t.settings.topOnEmptyHash)||"href"!=t.settings.targetAttribute)&&n.push(e)})),n}function M(t,n){n.stopPropagation(),n.preventDefault();var e=j.call(this,t);e&&this.scrollTo(e)}function H(t){var n=Math.max(1,this.settings.duration);if(this.settings.durationRelative){var e="number"==typeof this.settings.durationRelative?this.settings.durationRelative:1e3;n=Math.max(this.settings.duration,t*(n/e))}return this.settings.durationMin&&nthis.settings.durationMax&&(n=this.settings.durationMax),n}function P(t,n,e){var i=function(t,n,e){var i=n-e;return t<0?{to:E,px:-1*t}:t>i&&{to:x,px:-1*(i-t)}}(t,n,e),r=R.call(this),o=r.filter((function(t){return t.getAttribute(w)===E}))[0],s=r.filter((function(t){return t.getAttribute(w)===x}))[0];i&&o&&i.to===E?o.style.height=A(i.px):i&&s&&i.to===x?s.style.height=A(i.px):g(r,(function(t){t.style.removeProperty("height")}))}function R(){return Array.prototype.slice.call(this.container.children).filter((function(t){return t.hasAttribute(w)}))}function T(t,n,e,i,o){var s=this,a=t-n,c=a<0?-1*a:a,f=H.call(this,c),h=Math.min(f,m()-e),g=h/f,p="string"==typeof this.settings.easing?function(t,n){return Function('"use strict"; return ('+t+"("+n+"))")()}(this.settings.easing,g):this.settings.easing(g),y=n+a*p;this.settings.onScrollUpdate&&"function"==typeof this.settings.onScrollUpdate&&this.settings.onScrollUpdate({startPosition:n,currentPosition:y,endPosition:t}),l.scroll(0,y),i||(i=b()),o||(o=S()),P.call(this,y,i,o),h>=f?this.settings.onScrollEnd&&"function"==typeof this.settings.onScrollEnd&&this.settings.onScrollEnd({startPosition:n,endPosition:t}):r=u((function(){T.call(s,t,n,e,i,o)}))}return function(){function i(t,n){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,i);var e={container:s,targetAttribute:"href",topOnEmptyHash:!0,offset:null,duration:400,durationRelative:!1,durationMin:null,durationMax:null,easing:o,onScrollStart:null,onScrollUpdate:null,onScrollEnd:null};for(var r in n=n||e,e)Object.prototype.hasOwnProperty.call(e,r)&&!Object.prototype.hasOwnProperty.call(n,r)&&(n[r]=e[r]);this.settings=n;var l=c;"string"==typeof this.settings.container&&p(this.settings.container)?l=h(this.settings.container):"string"!=typeof this.settings.container&&y(this.settings.container)&&p(this.settings.container)&&(l=this.settings.container),l=l===s||l===a?c:l,this.container=l,this.elements="string"==typeof t?function(t){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:s).querySelectorAll(t)}(t,this.container):t}var u,v,A;return u=i,(v=[{key:"init",value:function(){var t=this;this.destroy();var n=s.createElement("div");n.setAttribute(w,E),this.container.insertBefore(n,this.container.firstChild);var e=s.createElement("div");e.setAttribute(w,x),this.container.appendChild(e),g(O.call(this),(function(n){n.addEventListener("click",M.bind(t,n),!1)})),g(["mousewheel","wheel","touchmove"],(function(n){l.addEventListener(n,(function(){t.cancelScroll()}))}))}},{key:"destroy",value:function(){var t=this;this.settings&&(this.cancelScroll(),g(R.call(this),(function(t){t.parentNode.removeChild(t)})),g(O.call(this),(function(n){n.removeEventListener("click",M.bind(t,n),!1)})))}},{key:"scrollTo",value:function(n){var e=d(),i=b(),r=S(),o=0;if(isNaN(n)){if(("object"===t(n)||"string"==typeof n)&&p(n,this.container)){"string"==typeof n&&(n=h(n,this.container));var s=n.getBoundingClientRect().top+e;o=i-st.length)&&(n=t.length);for(var e=0,i=new Array(n);e1&&void 0!==arguments[1]?arguments[1]:t;return e.querySelector(n)},g=function(t,n){Array.prototype.forEach.call(t,n)},y=function(n){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,i=!0;try{"string"==typeof n?p(n,e):d(n)&&e.contains(n)}catch(t){i=!1}return i},d=function(t){return function(t){try{return t instanceof Node}catch(n){return"object"===r(t)&&"number"==typeof t.nodeType&&"string"==typeof t.nodeName&&"object"===r(t.ownerDocument)}}(t)||function(t){try{return t instanceof HTMLElement}catch(n){return"object"===r(t)&&1===t.nodeType&&"object"===r(t.style)&&"object"===r(t.ownerDocument)}}(t)},v=function(){return i.pageYOffset||e.scrollTop||n.scrollTop},m=function(){return i.performance&&"now"in i.performance?performance.now():(new Date).getTime()},b=function(n){var e=new RegExp("("+location.hash+")?$");return(n.baseURI||t.URL).replace(e,"")},M=function(){return Math.max(e.scrollHeight,e.offsetHeight,e.clientHeight,n.scrollHeight,n.offsetHeight,n.clientHeight)},w=function(){return i.innerHeight||n.clientHeight||e.clientHeight},S=function(t){return t+"px"},O="data-scrolltosmooth-expand",I="top",A="bottom";function E(t){var n="";return"href"===this.settings.targetAttribute&&t.href?n=t.href.replace(b(t),""):t.getAttribute(this.settings.targetAttribute)&&(n=t.getAttribute(this.settings.targetAttribute)),this.settings.topOnEmptyHash&&"#"==n?this.container:(console.log(n,y(n,this.container)),y(n,this.container)?p(n,this.container):null)}function x(){var t=this,n=[];return g(this.elements,(function(e){E.call(t,e)&&("href"===t.settings.targetAttribute&&-1!=e.href.indexOf(b(e))&&-1!=e.href.indexOf("#")&&(""!=e.hash||t.settings.topOnEmptyHash)||"href"!=t.settings.targetAttribute)&&n.push(e)})),n}function P(t,n){n.stopPropagation(),n.preventDefault();var e=E.call(this,t);e&&this.scrollTo(e)}function j(t){var n=Math.max(1,this.settings.duration);if(this.settings.durationRelative){var e="number"==typeof this.settings.durationRelative?this.settings.durationRelative:1e3;n=Math.max(this.settings.duration,t*(n/e))}return this.settings.durationMin&&nthis.settings.durationMax&&(n=this.settings.durationMax),n}function C(t,n,e){var i=function(t,n,e){var i=n-e;return t<0?{to:I,px:-1*t}:t>i&&{to:A,px:-1*(i-t)}}(t,n,e),r=k.call(this),o=r.filter((function(t){return t.getAttribute(O)===I}))[0],s=r.filter((function(t){return t.getAttribute(O)===A}))[0];i&&o&&i.to===I?o.style.height=S(i.px):i&&s&&i.to===A?s.style.height=S(i.px):g(r,(function(t){t.style.removeProperty("height")}))}function k(){return Array.prototype.slice.call(this.container.children).filter((function(t){return t.hasAttribute(O)}))}function H(t,n,e,r,o){var s=this,a=t-n,c=a<0?-1*a:a,l=j.call(this,c),f=Math.min(l,m()-e),p=f/l,g="string"==typeof this.settings.easing?function(t,n){return Function('"use strict"; return ('+t+"("+n+"))")()}(this.settings.easing,p):this.settings.easing(p),y=n+a*g;this.settings.onScrollUpdate&&"function"==typeof this.settings.onScrollUpdate&&this.settings.onScrollUpdate({startPosition:n,currentPosition:y,endPosition:t}),i.scroll(0,y),r||(r=M()),o||(o=w()),C.call(this,y,r,o),f>=l?this.settings.onScrollEnd&&"function"==typeof this.settings.onScrollEnd&&this.settings.onScrollEnd({startPosition:n,endPosition:t}):u=h((function(){H.call(s,t,n,e,r,o)}))}var R=function(){function a(i,r){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,a);var o={container:t,targetAttribute:"href",topOnEmptyHash:!0,offset:null,duration:400,durationRelative:!1,durationMin:null,durationMax:null,easing:c,onScrollStart:null,onScrollUpdate:null,onScrollEnd:null};for(var s in r=r||o,o)Object.prototype.hasOwnProperty.call(o,s)&&!Object.prototype.hasOwnProperty.call(r,s)&&(r[s]=o[s]);this.settings=r;var u=e;"string"==typeof this.settings.container&&y(this.settings.container)?u=p(this.settings.container):"string"!=typeof this.settings.container&&d(this.settings.container)&&y(this.settings.container)&&(u=this.settings.container),u=u===t||u===n?e:u,this.container=u,this.elements="string"==typeof i?function(n){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:t).querySelectorAll(n)}(i,this.container):i}var l,h,b;return l=a,(h=[{key:"init",value:function(){var n=this;this.destroy();var e=t.createElement("div");e.setAttribute(O,I),this.container.insertBefore(e,this.container.firstChild);var r=t.createElement("div");r.setAttribute(O,A),this.container.appendChild(r),g(x.call(this),(function(t){t.addEventListener("click",P.bind(n,t),!1)})),g(["mousewheel","wheel","touchmove"],(function(t){i.addEventListener(t,(function(){n.cancelScroll()}))}))}},{key:"destroy",value:function(){var t=this;this.settings&&(this.cancelScroll(),g(k.call(this),(function(t){t.parentNode.removeChild(t)})),g(x.call(this),(function(n){n.removeEventListener("click",P.bind(t,n),!1)})))}},{key:"scrollTo",value:function(t){var n=v(),e=M(),i=w(),o=0;if(isNaN(t)){if(("object"===r(t)||"string"==typeof t)&&y(t,this.container)){"string"==typeof t&&(t=p(t,this.container));var s=t.getBoundingClientRect().top+n;o=e-s