-
Notifications
You must be signed in to change notification settings - Fork 1
/
svg-scroll.min.js
1 lines (1 loc) · 1.98 KB
/
svg-scroll.min.js
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.svgScroll=e()}(this,function(){"use strict";function t(t){this.element=document.querySelector(t)}function e(t){var e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(t);return[parseInt(e[1],16),parseInt(e[2],16),parseInt(e[3],16)]}function n(t){for(var e=[],n=0;n<3;n++)e.push(Math.clip(t[n],0,255).toString(16).substring(0,2));return"#"+e.join("")}function o(t,o){for(var r=e(o[0]),i=e(o[1]),s=[],l=0;l<3;l++)s.push(r[l]+t*(i[l]-r[l]));return n(s)}function r(){return(document.documentElement.scrollTop+document.body.scrollTop)/(document.documentElement.scrollHeight-document.documentElement.clientHeight)}function i(t,e){var n=r(),o=(n-t)/(e-t);return Math.clip(o,0,1)}function s(t,e,n){return n?o(t,e):e[0]+t*(e[1]-e[0])}function l(t,e,n,o,r){var s=i(t[0],t[1]);if(s>0&&s<1)if(s<.1)o(e[0],r);else if(s>.9)o(e[1],r);else{var l=n(s,e);o(l,r)}}return Math.clip=function(t,e,n){return Math.max(e,Math.min(t,n))},t.prototype.setProperty=function(t,e){"function"==typeof e?e(this.element,t):this.element.hasAttribute(e)?this.element.setAttribute(e,t):this.element.style[e]=t},t.prototype.setDashOffset=function(t){return function(e){var n=this.element.getTotalLength(),o=n*e;this.element.style.strokeDashoffset=n-t*o}},t.prototype.changeOnScroll=function(t,e,n){l(t,n,function(t,e){var n="string"==typeof e[0],o=n&&"#"===e[0].substring(0,1),r=o||!n?e:e.map(parseFloat),i=s(t,r,o),l=n?e[0].split(r[0])[1]:"";return String(i).concat(l)},this.setProperty.bind(this),e)},t.prototype.reveal=function(t,e,n){var o=n?-1:1;l(t,e,s,this.setDashOffset(o).bind(this))},t.prototype.hide=function(){var t=this.element.getTotalLength();this.element.style.strokeDasharray=t+" "+t,this.element.style.strokeDashoffset=t,this.element.getBoundingClientRect()},t.prototype.toggleClass=function(t,e){var n=i(t[0],t[1]);n>0&&n<1?this.element.classList.add(e):this.element.classList.remove(e)},{ScrollWrapper:t}});