@web3r/flowerkit
Version:
Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).
11 lines (10 loc) • 693 B
JavaScript
import{getDocument}from"ssr-window";
/**
* Computes the width of the browser's scrollbar in pixels.
*
* @returns {number} Scrollbar width in pixels
* @example
* const scrollbarWidth = getScrollbarWidth();
* console.log(scrollbarWidth); // => number
*/const getScrollbarWidth=()=>{const doc=getDocument();const outer=doc.createElement("div");outer.style.visibility="hidden";outer.style.overflow="scroll";outer.style.msOverflowStyle="scrollbar";doc.body.appendChild(outer);const inner=doc.createElement("div");outer.appendChild(inner);const w=outer.offsetWidth-inner.offsetWidth;outer.parentNode?.removeChild(outer);return w};export{getScrollbarWidth};
//# sourceMappingURL=index.mjs.map