Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

beautify-scrollbar

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beautify-scrollbar - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

dist/index.css

2

dist/index.js

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.BeautifyScrollbar=e():t.BeautifyScrollbar=e()}(window,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";i.r(e),i(2);var n="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};function o(t){var e=window.document.createElement("div");return e.className=t,e}function s(t){t.remove?t.remove():t.parentNode&&t.parentNode.removeChild(t)}function h(t,e){if("object"===(void 0===e?"undefined":n(e))){for(var i in e){var o=e[i];"number"==typeof o&&(o+="px"),t.style[i]=o}return t}}function r(t){var e=(t.getAttribute("class")||"").replace(/^\s+|\s+$/g,"").split(/\s+/);return""===e[0]&&e.shift(),e}function l(t,e){if(e&&"string"==typeof e&&t&&t.nodeName){for(var i=[],n=r(t),o=e.split(" "),s=0;s<o.length;s++){var h=o[s];h&&(t.classList?t.classList.remove(h):n.splice(n.indexOf(h),1))}i=n,t.classList||t.setAttribute("class",i.join(" "))}}function a(t,e){if(e&&"string"==typeof e&&t&&t.nodeName){for(var i=r(t),n=e.split(" "),o=0;o<n.length;o++){var s=n[o];s&&(t.classList?t.classList.add(s):i.push(s))}t.classList||t.setAttribute("class",i.join(" "))}}var c=function(t){if("function"==typeof window.CustomEvent)return new CustomEvent(t,{bubbles:!1,cancelable:!1,detail:null});var e=document.createEvent("CustomEvent");return e.initCustomEvent(t,!1,!1,null),e},u=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),"string"==typeof e&&(e=document.querySelector(e)),!e||!e.nodeName)throw new Error("no element is specified to initialize BeautifyScrollBar");if(this.element=e,this.ownerDocument=this.element.ownerDocument||document,this.rect=this.element.getBoundingClientRect(),!this.rect.height)throw new Error("the height of container can not be 0");this.options=Object.assign({},{wheelSpeed:1,threshold:0,shownScrollbarX:!0,shownScrollbarY:!0,maxThumbXLength:void 0,maxThumbYLength:void 0},i,{threshold:isNaN(i.threshold)||i.threshold<=0?0:i.threshold,wheelSpeed:isNaN(i.wheelSpeed)||i.wheelSpeed<=0?1:i.wheelSpeed,maxThumbXLength:isNaN(i.maxThumbXLength)||i.maxThumbXLength<=0?void 0:i.maxThumbXLength,maxThumbYLength:isNaN(i.maxThumbYLength)||i.maxThumbYLength<=0?void 0:i.maxThumbYLength}),this.lastScrollLeft=0,this.lastScrollTop=0,this.xBar=null,this.xThumb=null,this.xThumbWidth=null,this.yBar=null,this.yThumb=null,this.yThumbHeight=null,this.startingMousePageY=0,this.startingMousePageX=0,this.startingScrollTop=0,this.startingScrollLeft=0,this.yScrollFactor=0,this.xScrollFactor=0,this.dragDirect="",this.wheelEventHandler=this._wheelEventHandler.bind(this),this.docMouseMoveHandler=this._docMouseMoveHandler.bind(this),this.docMouseUpHandler=this._docMouseUpHandler.bind(this),a(this.element,"beautify-scroll-container"),this._computed(),this._createBarEle(),this._bindEvent()}return t.prototype._computed=function(){this.contentWidth=isNaN(this.options.contentWidth)?Math.max(this.element.scrollWidth,this.rect.width):this.options.contentWidth,this.contentHeight=isNaN(this.options.contentHeight)?Math.max(this.element.scrollHeight,this.rect.height):this.options.contentHeight,this.containerWidth=this.rect.width,this.containerHeight=this.rect.height,this.maxScrollLeft=this.contentWidth-this.containerWidth,this.maxScrollTop=this.contentHeight-this.containerHeight},t.prototype._createBarEle=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.maxScrollTop>0&&this.options.shownScrollbarY){var e=0,i=0,n=0;this.yBar||(this.yBar=o("beautify-scroll__y-bar"),this.element.appendChild(this.yBar),this.yBar.setAttribute("tabindex",-1),this.yThumb=o("beautify-scroll__y-thumb"),this.yBar.appendChild(this.yThumb),this.yThumb.addEventListener("mousedown",this._mouseDownHandler.bind(this,"y"),!1)),t&&(e=this.yBar.style.top,i=this.yBar.style.right,n=this.yThumb.style.top),h(this.yBar,{height:this.containerHeight,right:i,top:e});var s=parseInt(this.containerHeight*this.containerHeight/this.contentHeight,10);this.yThumbHeight=isNaN(this.options.maxThumbYLength)||s<=this.options.maxThumbYLength?s:this.options.maxThumbYLength,h(this.yThumb,{top:n,height:this.yThumbHeight}),this.yScrollFactor=(this.contentHeight-this.containerHeight)/(this.containerHeight-this.yThumbHeight)}if(this.maxScrollLeft>0&&this.options.shownScrollbarX){var r=0,l=0,a=0;this.xBar||(this.xBar=o("beautify-scroll__x-bar"),this.element.appendChild(this.xBar),this.xBar.setAttribute("tabindex",-1),this.xThumb=o("beautify-scroll__x-thumb"),this.xBar.appendChild(this.xThumb),this.xThumb.addEventListener("mousedown",this._mouseDownHandler.bind(this,"x"),!1)),t&&(r=this.xBar.style.left,l=this.xBar.style.bottom,a=this.xThumb.style.left),h(this.xBar,{left:r,width:this.containerWidth,bottom:l});var c=parseInt(this.containerWidth*this.containerWidth/this.contentWidth,10);this.xThumbWidth=isNaN(this.options.maxThumbXLength)||c<=this.options.maxThumbXLength?c:this.options.maxThumbXLength,h(this.xThumb,{left:a,width:this.xThumbWidth}),this.xScrollFactor=(this.contentWidth-this.containerWidth)/(this.containerWidth-this.xThumbWidth)}},t.prototype._bindEvent=function(){var t=this;void 0!==window.onwheel?this.element.addEventListener("wheel",this.wheelEventHandler,!1):void 0!==window.onmousewheel&&this.element.addEventListener("mousewheel",this.wheelEventHandler,!1),this.element.addEventListener("mouseenter",function(){t.yThumb&&a(t.yThumb,"shown"),t.xThumb&&a(t.xThumb,"shown")},!1),this.element.addEventListener("mouseleave",function(){t.yThumb&&l(t.yThumb,"shown"),t.xThumb&&l(t.xThumb,"shown")},!1)},t.prototype._handleScrollDiff=function(){var t=this.element.scrollTop-this.lastScrollTop;0===this.element.scrollTop&&t&&this.element.dispatchEvent(c("bs-y-reach-start")),this.element.scrollTop===this.maxScrollTop&&t&&this.element.dispatchEvent(c("bs-y-reach-end")),0===this.element.scrollLeft&&t&&this.element.dispatchEvent(c("bs-x-reach-start")),this.element.scrollLeft===this.maxScrollLeft&&t&&this.element.dispatchEvent(c("bs-x-reach-end")),this.element.scrollHeight-this.element.scrollTop-this.rect.height<=this.options.threshold&&this.element.dispatchEvent(c("bs-threshold"))},t.prototype._updateScrollBarStyle=function(){this.yBar&&h(this.yBar,{top:this.element.scrollTop,height:this.containerHeight,right:-this.element.scrollLeft});var t=parseInt(this.element.scrollTop*(this.containerHeight-this.yThumbHeight)/this.maxScrollTop,10);this.yThumb&&h(this.yThumb,{top:t,height:this.yThumbHeight}),this.xBar&&h(this.xBar,{left:this.element.scrollLeft,width:this.containerWidth,bottom:-this.element.scrollTop});var e=parseInt(this.element.scrollLeft*(this.containerWidth-this.xThumbWidth)/this.maxScrollLeft,10);this.xThumb&&h(this.xThumb,{left:e,width:this.xThumbWidth})},t.prototype._docMouseMoveHandler=function(t){if(t.stopPropagation(),t.preventDefault(),this.lastScrollLeft=this.element.scrollLeft,this.lastScrollTop=this.element.scrollTop,"x"===this.dragDirect){var e=this.startingScrollLeft+this.xScrollFactor*(t.pageX-this.startingMousePageX);this.element.scrollLeft=e>this.maxScrollLeft?this.maxScrollLeft:e}else if("y"===this.dragDirect){var i=this.startingScrollTop+this.yScrollFactor*(t.pageY-this.startingMousePageY);this.element.scrollTop=i>this.maxScrollTop?this.maxScrollTop:i}this._handleScrollDiff(),this._updateScrollBarStyle()},t.prototype._docMouseUpHandler=function(t){t.stopPropagation(),t.preventDefault(),"x"===this.dragDirect&&this.xThumb&&l(this.xThumb,"focus"),"y"===this.dragDirect&&this.yThumb&&l(this.yThumb,"focus"),this.ownerDocument.removeEventListener("mousemove",this.docMouseMoveHandler),this.ownerDocument.removeEventListener("mouseup",this.docMouseUpHandler)},t.prototype._mouseDownHandler=function(t,e){e.stopPropagation(),e.preventDefault(),"x"===t&&(this.startingMousePageX=e.pageX,this.startingScrollLeft=this.element.scrollLeft,this.xThumb&&a(this.xThumb,"focus")),"y"===t&&(this.startingMousePageY=e.pageY,this.startingScrollTop=this.element.scrollTop,this.yThumb&&a(this.yThumb,"focus")),this.dragDirect=t,this.ownerDocument.addEventListener("mousemove",this.docMouseMoveHandler,!1),this.ownerDocument.addEventListener("mouseup",this.docMouseUpHandler,!1)},t.prototype._wheelEventHandler=function(t){t.stopPropagation(),this.maxScrollTop>0&&t.preventDefault();var e=function(t){var e=t.deltaX,i=-1*t.deltaY;return void 0!==e&&void 0!==i||(e=-1*t.wheelDeltaX/6,i=t.wheelDeltaY/6),t.deltaMode&&1===t.deltaMode&&(e*=10,i*=10),e!=e&&i!=i&&(e=0,i=t.wheelDelta),t.shiftKey?[-i,-e]:[e,i]}(t),i=e[0],n=e[1];if(this.lastScrollLeft=this.element.scrollLeft,this.lastScrollTop=this.element.scrollTop,this._shouldUpdateScrollLeft(i)){var o=this.element.scrollLeft+i*this.options.wheelSpeed;this.element.scrollLeft=o>this.maxScrollLeft?this.maxScrollLeft:o}if(this._shouldUpdateScrollTop(n)){var s=this.element.scrollTop-n*this.options.wheelSpeed;this.element.scrollTop=s>this.maxScrollTop?this.maxScrollTop:s}this._handleScrollDiff(),this._updateScrollBarStyle()},t.prototype._shouldUpdateScrollLeft=function(t){return!(0===this.element.scrollLeft&&t<=0||this.element.scrollLeft===this.maxScrollLeft&&t>0)},t.prototype._shouldUpdateScrollTop=function(t){return!(0===this.element.scrollTop&&t>=0||this.element.scrollTop===this.maxScrollTop&&t<0)},t.prototype._unbindEvent=function(){this.element.removeEventListener("mouseenter"),this.element.removeEventListener("mouseleave"),this.element.removeEventListener("wheel",this.wheelEventHandler),this.element.removeEventListener("mousewheel",this.wheelEventHandler),this.xThumb&&this.xThumb.removeAllEventListener("mousedown"),this.yThumb&&this.yThumb.removeAllEventListener("mousedown")},t.prototype.update=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.element&&(this.options=Object.assign({},this.options,t),this._computed(),this._createBarEle(!0))},t.prototype.destroy=function(){this.element&&(this._unbindEvent(),l(this.element,"beautify-scroll-container"),this.element=null,this.yBar&&s(this.yBar),this.xBar&&s(this.xBar),this.xBar=null,this.xThumb=null,this.xThumbWidth=null,this.yBar=null,this.yThumb=null,this.yThumbHeight=null,this.wheelEventHandler=null,this.docMouseMoveHandler=null,this.docMouseUpHandler=null)},t}();e.default=u},function(t,e){t.exports=function(t){var e=[];return e.toString=function(){return this.map(function(e){var i=function(t,e){var i,n=t[1]||"",o=t[3];if(!o)return n;if(e&&"function"==typeof btoa){var s=(i=o,"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */"),h=o.sources.map(function(t){return"/*# sourceURL="+o.sourceRoot+t+" */"});return[n].concat(h).concat([s]).join("\n")}return[n].join("\n")}(e,t);return e[2]?"@media "+e[2]+"{"+i+"}":i}).join("")},e.i=function(t,i){"string"==typeof t&&(t=[[null,t,""]]);for(var n={},o=0;o<this.length;o++){var s=this[o][0];"number"==typeof s&&(n[s]=!0)}for(o=0;o<t.length;o++){var h=t[o];"number"==typeof h[0]&&n[h[0]]||(i&&!h[2]?h[2]=i:i&&(h[2]="("+h[2]+") and ("+i+")"),e.push(h))}},e}},function(t,e,i){(t.exports=i(1)(!1)).push([t.i,"/* scrollbar start */\n.beautify-scroll-container {\n position: relative !important;\n overflow: hidden !important;\n -webkit-box-sizing: border-box !important;\n box-sizing: border-box !important;\n overflow-anchor: none;\n}\n.beautify-scroll__y-bar,\n.beautify-scroll__x-bar {\n position: absolute;\n z-index: 100;\n background-color: transparent;\n}\n.beautify-scroll__y-bar {\n width: 10px;\n}\n.beautify-scroll__x-bar {\n height: 10px;\n}\n.beautify-scroll__y-thumb,\n.beautify-scroll__x-thumb {\n position: absolute;\n border-radius: 6px;\n background-color: #B8B8B8;\n opacity: 0;\n -webkit-transition: all .2s linear;\n -o-transition: all .2s linear;\n transition: all .2s linear;\n}\n.beautify-scroll__y-thumb:hover,\n.beautify-scroll__x-thumb:hover {\n background-color: #777777;\n}\n.beautify-scroll__y-thumb.shown,\n.beautify-scroll__x-thumb.shown {\n opacity: 1;\n}\n.beautify-scroll__y-thumb.focus,\n.beautify-scroll__x-thumb.focus {\n opacity: 1;\n background-color: #777777;\n}\n.beautify-scroll__x-thumb {\n height: 7px;\n bottom: 0;\n}\n.beautify-scroll__y-thumb {\n width: 7px;\n right: 0;\n}\n/* scrollbar end */\n",""])}])});
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.BeautifyScrollbar=e():t.BeautifyScrollbar=e()}(window,function(){return function(t){var e={};function i(s){if(e[s])return e[s].exports;var h=e[s]={i:s,l:!1,exports:{}};return t[s].call(h.exports,h,h.exports,i),h.l=!0,h.exports}return i.m=t,i.c=e,i.d=function(t,e,s){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:s})},i.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";i.r(e),i(2);var s="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};function h(t){var e=window.document.createElement("div");return e.className=t,e}function o(t){t.remove?t.remove():t.parentNode&&t.parentNode.removeChild(t)}function n(t,e){if("object"===(void 0===e?"undefined":s(e))){for(var i in e){var h=e[i];"number"==typeof h&&(h+="px"),t.style[i]=h}return t}}function l(t){var e=(t.getAttribute("class")||"").replace(/^\s+|\s+$/g,"").split(/\s+/);return""===e[0]&&e.shift(),e}function r(t,e){if(e&&"string"==typeof e&&t&&t.nodeName){for(var i=[],s=l(t),h=e.split(" "),o=0;o<h.length;o++){var n=h[o];n&&(t.classList?t.classList.remove(n):s.splice(s.indexOf(n),1))}i=s,t.classList||t.setAttribute("class",i.join(" "))}}function a(t,e){if(e&&"string"==typeof e&&t&&t.nodeName){for(var i=l(t),s=e.split(" "),h=0;h<s.length;h++){var o=s[h];o&&(t.classList?t.classList.add(o):i.push(o))}t.classList||t.setAttribute("class",i.join(" "))}}var u=function(t){if("function"==typeof window.CustomEvent)return new CustomEvent(t,{bubbles:!1,cancelable:!1,detail:null});var e=document.createEvent("CustomEvent");return e.initCustomEvent(t,!1,!1,null),e},c=function(){function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),"string"==typeof e&&(e=document.querySelector(e)),!e||!e.nodeName)throw new Error("no element is specified to initialize BeautifyScrollBar");if(this.element=e,this.ownerDocument=this.element.ownerDocument||document,this.rect=this.element.getBoundingClientRect(),!this.rect.height)throw new Error("the height of container can not be 0");this.options=Object.assign({},{wheelSpeed:1,threshold:0,shownScrollbarX:!0,shownScrollbarY:!0,maxThumbXLength:void 0,maxThumbYLength:void 0},i,{threshold:isNaN(i.threshold)||i.threshold<=0?0:i.threshold,wheelSpeed:isNaN(i.wheelSpeed)||i.wheelSpeed<=0?1:i.wheelSpeed,maxThumbXLength:isNaN(i.maxThumbXLength)||i.maxThumbXLength<=0?void 0:i.maxThumbXLength,maxThumbYLength:isNaN(i.maxThumbYLength)||i.maxThumbYLength<=0?void 0:i.maxThumbYLength}),this.lastScrollLeft=0,this.lastScrollTop=0,this.xBar=null,this.xThumb=null,this.xThumbWidth=null,this.yBar=null,this.yThumb=null,this.yThumbHeight=null,this.startingMousePageY=0,this.startingMousePageX=0,this.startingScrollTop=0,this.startingScrollLeft=0,this.yScrollFactor=0,this.xScrollFactor=0,this.dragDirect="",this.wheelEventHandler=this._wheelEventHandler.bind(this),this.docMouseMoveHandler=this._docMouseMoveHandler.bind(this),this.docMouseUpHandler=this._docMouseUpHandler.bind(this),this.downXThumb=this._mouseDownHandler.bind(this,"x"),this.downYThumb=this._mouseDownHandler.bind(this,"y"),this.handleMouseEnter=this._handlerEnter.bind(this),this.handleMouseLeave=this._handlerLeave.bind(this),a(this.element,"beautify-scroll-container"),this._computed(),this._createBarEle(),this._bindEvent()}return t.prototype._computed=function(){this.contentWidth=isNaN(this.options.contentWidth)?Math.max(this.element.scrollWidth,this.rect.width):this.options.contentWidth,this.contentHeight=isNaN(this.options.contentHeight)?Math.max(this.element.scrollHeight,this.rect.height):this.options.contentHeight,this.containerWidth=this.rect.width,this.containerHeight=this.rect.height,this.maxScrollLeft=this.contentWidth-this.containerWidth,this.maxScrollTop=this.contentHeight-this.containerHeight},t.prototype._createBarEle=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];if(this.maxScrollTop>0&&this.options.shownScrollbarY){var e=0,i=0,s=0;this.yBar||(this.yBar=h("beautify-scroll__y-bar"),this.element.appendChild(this.yBar),this.yBar.setAttribute("tabindex",-1),this.yThumb=h("beautify-scroll__y-thumb"),this.yBar.appendChild(this.yThumb),this.yThumb.addEventListener("mousedown",this.downYThumb,!1)),t&&(e=this.yBar.style.top,i=this.yBar.style.right,s=this.yThumb.style.top),n(this.yBar,{height:this.containerHeight,right:i,top:e});var o=parseInt(this.containerHeight*this.containerHeight/this.contentHeight,10);this.yThumbHeight=isNaN(this.options.maxThumbYLength)||o<=this.options.maxThumbYLength?o:this.options.maxThumbYLength,n(this.yThumb,{top:s,height:this.yThumbHeight}),this.yScrollFactor=(this.contentHeight-this.containerHeight)/(this.containerHeight-this.yThumbHeight)}if(this.maxScrollLeft>0&&this.options.shownScrollbarX){var l=0,r=0,a=0;this.xBar||(this.xBar=h("beautify-scroll__x-bar"),this.element.appendChild(this.xBar),this.xBar.setAttribute("tabindex",-1),this.xThumb=h("beautify-scroll__x-thumb"),this.xBar.appendChild(this.xThumb),this.xThumb.addEventListener("mousedown",this.downXThumb,!1)),t&&(l=this.xBar.style.left,r=this.xBar.style.bottom,a=this.xThumb.style.left),n(this.xBar,{left:l,width:this.containerWidth,bottom:r});var u=parseInt(this.containerWidth*this.containerWidth/this.contentWidth,10);this.xThumbWidth=isNaN(this.options.maxThumbXLength)||u<=this.options.maxThumbXLength?u:this.options.maxThumbXLength,n(this.xThumb,{left:a,width:this.xThumbWidth}),this.xScrollFactor=(this.contentWidth-this.containerWidth)/(this.containerWidth-this.xThumbWidth)}},t.prototype._handlerEnter=function(){this.yThumb&&a(this.yThumb,"shown"),this.xThumb&&a(this.xThumb,"shown")},t.prototype._handlerLeave=function(){this.yThumb&&r(this.yThumb,"shown"),this.xThumb&&r(this.xThumb,"shown")},t.prototype._bindEvent=function(){void 0!==window.onwheel?this.element.addEventListener("wheel",this.wheelEventHandler,!1):void 0!==window.onmousewheel&&this.element.addEventListener("mousewheel",this.wheelEventHandler,!1),this.element.addEventListener("mouseenter",this.handleMouseEnter,!1),this.element.addEventListener("mouseleave",this.handleMouseLeave,!1)},t.prototype._handleScrollDiff=function(){var t=this.element.scrollTop-this.lastScrollTop,e=this.element.scrollLeft-this.lastScrollLeft;0===this.element.scrollTop&&t&&this.element.dispatchEvent(u("bs-y-reach-start")),this.element.scrollTop===this.maxScrollTop&&t&&this.element.dispatchEvent(u("bs-y-reach-end")),0===this.element.scrollLeft&&e&&this.element.dispatchEvent(u("bs-x-reach-start")),this.element.scrollLeft===this.maxScrollLeft&&e&&this.element.dispatchEvent(u("bs-x-reach-end")),this.element.scrollHeight-this.element.scrollTop-this.rect.height<=this.options.threshold&&this.element.dispatchEvent(u("bs-threshold"))},t.prototype._updateScrollBarStyle=function(){this.yBar&&n(this.yBar,{top:this.element.scrollTop,height:this.containerHeight,right:-this.element.scrollLeft});var t=parseInt(this.element.scrollTop*(this.containerHeight-this.yThumbHeight)/this.maxScrollTop,10);this.yThumb&&n(this.yThumb,{top:t,height:this.yThumbHeight}),this.xBar&&n(this.xBar,{left:this.element.scrollLeft,width:this.containerWidth,bottom:-this.element.scrollTop});var e=parseInt(this.element.scrollLeft*(this.containerWidth-this.xThumbWidth)/this.maxScrollLeft,10);this.xThumb&&n(this.xThumb,{left:e,width:this.xThumbWidth});var i=this.element.scrollTop-this.lastScrollTop,s=this.element.scrollLeft-this.lastScrollLeft;(i||s)&&this.element.dispatchEvent(u("bs-update-scroll-value"))},t.prototype._docMouseMoveHandler=function(t){if(t.stopPropagation(),t.preventDefault(),this.lastScrollLeft=this.element.scrollLeft,this.lastScrollTop=this.element.scrollTop,"x"===this.dragDirect){var e=this.startingScrollLeft+this.xScrollFactor*(t.pageX-this.startingMousePageX);this.element.scrollLeft=e>this.maxScrollLeft?this.maxScrollLeft:e}else if("y"===this.dragDirect){var i=this.startingScrollTop+this.yScrollFactor*(t.pageY-this.startingMousePageY);this.element.scrollTop=i>this.maxScrollTop?this.maxScrollTop:i}this._handleScrollDiff(),this._updateScrollBarStyle()},t.prototype._docMouseUpHandler=function(t){t.stopPropagation(),t.preventDefault(),"x"===this.dragDirect&&this.xThumb&&r(this.xThumb,"focus"),"y"===this.dragDirect&&this.yThumb&&r(this.yThumb,"focus"),this.ownerDocument.removeEventListener("mousemove",this.docMouseMoveHandler),this.ownerDocument.removeEventListener("mouseup",this.docMouseUpHandler)},t.prototype._mouseDownHandler=function(t,e){e.stopPropagation(),e.preventDefault(),"x"===t&&(this.startingMousePageX=e.pageX,this.startingScrollLeft=this.element.scrollLeft,this.xThumb&&a(this.xThumb,"focus")),"y"===t&&(this.startingMousePageY=e.pageY,this.startingScrollTop=this.element.scrollTop,this.yThumb&&a(this.yThumb,"focus")),this.dragDirect=t,this.ownerDocument.addEventListener("mousemove",this.docMouseMoveHandler,!1),this.ownerDocument.addEventListener("mouseup",this.docMouseUpHandler,!1)},t.prototype._wheelEventHandler=function(t){t.stopPropagation(),this.maxScrollTop>0&&t.preventDefault();var e=function(t){var e=t.deltaX,i=-1*t.deltaY;return void 0!==e&&void 0!==i||(e=-1*t.wheelDeltaX/6,i=t.wheelDeltaY/6),t.deltaMode&&1===t.deltaMode&&(e*=10,i*=10),e!=e&&i!=i&&(e=0,i=t.wheelDelta),t.shiftKey?[-i,-e]:[e,i]}(t),i=e[0],s=e[1];if(this.lastScrollLeft=this.element.scrollLeft,this.lastScrollTop=this.element.scrollTop,this._shouldUpdateScrollLeft(i)){var h=this.element.scrollLeft+i*this.options.wheelSpeed;this.element.scrollLeft=h>this.maxScrollLeft?this.maxScrollLeft:h}if(this._shouldUpdateScrollTop(s)){var o=this.element.scrollTop-s*this.options.wheelSpeed;this.element.scrollTop=o>this.maxScrollTop?this.maxScrollTop:o}this._handleScrollDiff(),this._updateScrollBarStyle()},t.prototype._shouldUpdateScrollLeft=function(t){return!(0===this.element.scrollLeft&&t<=0||this.element.scrollLeft===this.maxScrollLeft&&t>0)},t.prototype._shouldUpdateScrollTop=function(t){return!(0===this.element.scrollTop&&t>=0||this.element.scrollTop===this.maxScrollTop&&t<0)},t.prototype._unbindEvent=function(){this.element.removeEventListener("mouseenter",this.handleMouseEnter,!1),this.element.removeEventListener("mouseleave",this.handleMouseLeave,!1),this.element.removeEventListener("wheel",this.wheelEventHandler,!1),this.element.removeEventListener("mousewheel",this.wheelEventHandler,!1),this.xThumb&&this.xThumb.removeEventListener("mousedown",this.downXThumb,!1),this.yThumb&&this.yThumb.removeEventListener("mousedown",this.downYThumb,!1)},t.prototype.update=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.element&&(this.options=Object.assign({},this.options,t),this._computed(),this._createBarEle(!0))},t.prototype.destroy=function(){this.element&&(this._unbindEvent(),r(this.element,"beautify-scroll-container"),this.element=null,this.yBar&&o(this.yBar),this.xBar&&o(this.xBar),this.xBar=null,this.xThumb=null,this.xThumbWidth=null,this.yBar=null,this.yThumb=null,this.yThumbHeight=null,this.wheelEventHandler=null,this.docMouseMoveHandler=null,this.docMouseUpHandler=null,this.downXThumb=null,this.downYThumb=null,this.handleMouseEnter=null,this.handleMouseLeave=null)},t}();e.default=c},,function(t,e){}])});
{
"name": "beautify-scrollbar",
"version": "1.0.0",
"version": "1.0.1",
"description": "Beautify browser's scrollbars",

@@ -5,0 +5,0 @@ "author": "dwqs",

@@ -21,2 +21,3 @@ [![build pass](https://api.travis-ci.org/dwqs/beautify-scrollbar.svg?branch=master)](https://travis-ci.org/dwqs/beautify-scrollbar) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com) ![npm-version](https://img.shields.io/npm/v/beautify-scrollbar.svg) ![license](https://img.shields.io/npm/l/beautify-scrollbar.svg)

```
import 'beautify-scrollbar/dist/index.css';
import BeautifyScrollbar from 'beautify-scrollbar';

@@ -102,2 +103,5 @@

### `bs-update-scroll-value`
This event fires when scrollLeft or scrollTop is updated.
### `bs-threshold`

@@ -104,0 +108,0 @@ This event fires when `diff-value` is lte the `options.threshold`.

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