smooth-scrollbar
Version:
Customize scrollbar in modern browsers with smooth scrolling experience.
30 lines • 1.92 kB
JavaScript
var TRACK_BG = 'rgba(222, 222, 222, .75)';
var THUMB_BG = 'rgba(0, 0, 0, .5)';
// sets content's display type to `flow-root` to suppress margin collapsing
var SCROLLBAR_STYLE = "\n[data-scrollbar] {\n display: block;\n position: relative;\n}\n\n.scroll-content {\n display: flow-root;\n -webkit-transform: translate3d(0, 0, 0);\n transform: translate3d(0, 0, 0);\n}\n\n.scrollbar-track {\n position: absolute;\n opacity: 0;\n z-index: 1;\n background: " + TRACK_BG + ";\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n -webkit-transition: opacity 0.5s 0.5s ease-out;\n transition: opacity 0.5s 0.5s ease-out;\n}\n.scrollbar-track.show,\n.scrollbar-track:hover {\n opacity: 1;\n -webkit-transition-delay: 0s;\n transition-delay: 0s;\n}\n\n.scrollbar-track-x {\n bottom: 0;\n left: 0;\n width: 100%;\n height: 8px;\n}\n.scrollbar-track-y {\n top: 0;\n right: 0;\n width: 8px;\n height: 100%;\n}\n.scrollbar-thumb {\n position: absolute;\n top: 0;\n left: 0;\n width: 8px;\n height: 8px;\n background: " + THUMB_BG + ";\n border-radius: 4px;\n}\n";
var STYLE_ID = 'smooth-scrollbar-style';
var isStyleAttached = false;
export function attachStyle() {
if (isStyleAttached || typeof window === 'undefined') {
return;
}
var styleEl = document.createElement('style');
styleEl.id = STYLE_ID;
styleEl.textContent = SCROLLBAR_STYLE;
if (document.head) {
document.head.appendChild(styleEl);
}
isStyleAttached = true;
}
export function detachStyle() {
if (!isStyleAttached || typeof window === 'undefined') {
return;
}
var styleEl = document.getElementById(STYLE_ID);
if (!styleEl || !styleEl.parentNode) {
return;
}
styleEl.parentNode.removeChild(styleEl);
isStyleAttached = false;
}
//# sourceMappingURL=style.js.map