-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.min.js
1 lines (1 loc) · 1.7 KB
/
index.min.js
1
var Config={content:"↑",title:"Top",id:"js-scrolltopable",visibleClass:"js-scrolltopable--visible",activeClass:"js-scrolltopable--active",extraClass:"noprint",hideBeforeTop:500,showBeforeBottom:500,showAfterUp:200,hideAfterDown:200,activeTime:0,scrollActionDelay:200};let Scrolltopable=function(){function t(){window.clearTimeout(e),e=window.setTimeout(function(){var e,o,t;i.classList.contains(Config.activeClass)||(o=(e=l())-n,t=Math.abs(o),s()-e<Config.showBeforeBottom?a():e<=Config.hideBeforeTop||0<o&&t>Config.hideAfterDown?c():t>Config.showAfterUp&&a(),n=e)},Config.scrollActionDelay)}let e=null,i=null,o=!1,n=0,l=function(){return document.body.scrollTop||document.documentElement.scrollTop},s=function(){var e=document.body,o=document.documentElement;return Math.max(e.scrollHeight,e.offsetHeight,o.clientHeight,o.scrollHeight,o.offsetHeight)-Math.max(o.clientHeight,window.innerHeight||0)},c=function(){o=!1,i.classList.remove(Config.visibleClass)},a=function(){o=!0,i.classList.add(Config.visibleClass)};return{init:function(e){Config={...Config,...e};{(i=document.createElement("a")).id=Config.id,i.title=Config.title,i.className=Config.extraClass+" "+Config.id;let e=document.createElement("span");e.innerHTML=Config.content,i.appendChild(e),document.body.appendChild(i)}{Config.styles;const o=document.createElement("style");o.innerHTML=Config.styles,document.head.appendChild(o)}window.addEventListener("scroll",t,!1),i.addEventListener("click",e=>{window.scrollTo(0,0),0!=Config.activeTime&&(i.classList.add(Config.activeClass),window.setTimeout(()=>{i.classList.remove(Config.activeClass),c()},Config.activeTime))}),(e=l())<=Config.hideBeforeTop||(a(),n=e)}}},instance=new Scrolltopable;export{instance as Scrolltopable};