forked from buzinas/simple-scrollbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-scrollbar.min.js
1 lines (1 loc) · 1.94 KB
/
simple-scrollbar.min.js
1
!function(a,b){function d(a){a.hasOwnProperty("data-simple-scrollbar")||Object.defineProperty(a,"data-simple-scrollbar",new SimpleScrollbar(a))}function e(a,d){function f(a){var b=a.pageY-e;e=a.pageY,c(function(){d.el.scrollTop+=b/d.scrollRatio})}function g(){a.classList.remove("ss-grabbed"),b.body.classList.remove("ss-grabbed"),b.removeEventListener("mousemove",f),b.removeEventListener("mouseup",g)}var e;a.addEventListener("mousedown",function(c){return e=c.pageY,a.classList.add("ss-grabbed"),b.body.classList.add("ss-grabbed"),b.addEventListener("mousemove",f),b.addEventListener("mouseup",g),!1})}function f(a){for(this.target=a,this.bar='<div class="ss-scroll">',this.wrapper=b.createElement("div"),this.wrapper.setAttribute("class","ss-wrapper"),this.el=b.createElement("div"),this.el.setAttribute("class","ss-content"),this.wrapper.appendChild(this.el);this.target.firstChild;)this.el.appendChild(this.target.firstChild);this.target.appendChild(this.wrapper),this.target.insertAdjacentHTML("beforeend",this.bar),this.bar=this.target.lastChild,e(this.bar,this),this.moveBar(),this.el.addEventListener("scroll",this.moveBar.bind(this)),this.el.addEventListener("mouseenter",this.moveBar.bind(this)),this.target.classList.add("ss-container");var c=window.getComputedStyle(a);"0px"===c.height&&"0px"!==c["max-height"]&&(a.style.height=c["max-height"])}function g(){for(var a=b.querySelectorAll("*[ss-container]"),c=0;c<a.length;c++)d(a[c])}var c=a.requestAnimationFrame||a.setImmediate||function(a){return setTimeout(a,0)};f.prototype={moveBar:function(a){var b=this.el.scrollHeight,d=this.el.clientHeight,e=this;this.scrollRatio=d/b,c(function(){e.scrollRatio>=1?e.bar.classList.add("ss-hidden"):(e.bar.classList.remove("ss-hidden"),e.bar.style.cssText="height:"+100*e.scrollRatio+"%; top:"+e.el.scrollTop/b*100+"%;right:-"+(e.target.clientWidth-e.bar.clientWidth)+"px;")})}},b.addEventListener("DOMContentLoaded",g),f.initEl=d,f.initAll=g,a.SimpleScrollbar=f}(window,document);