simple function to retrieve the browser scrollbar width


101.1.34 years ago5 years agoMinified + gzip package size for @loopmode/scrollbarwidth in KB



Extremely simple script for getting the current width of the browser window scrollbar.

If there is no scrollbar when invoked, 0 is returned.


# using npm
npm install @loopmode/scrollbarwidth --save

# using yarn
yarn add @loopmode/scrollbarwidth


You can provide a DOM element as argument to check it for its scrollbar width. When you call the function without arguments, it returns the width of the global window scrollbar. You can require/import it any way you wish, and you can also access window.scrollbarwidth.

import scrollbarwidth from '@loopmode/scrollbarwidth';

var windowHasScrollbar = scrollbarwidth() > 0;
var elHasScrollbar = scrollbarwidth(document.querySelector('.my-element')) > 0;

Have a look at the code at github. It's ridiculously simple.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.