https://github.com/loopmode/scrollbarwidth
Very simple script for getting the width of the browser scrollbar
https://github.com/loopmode/scrollbarwidth
Last synced: 5 months ago
JSON representation
Very simple script for getting the width of the browser scrollbar
- Host: GitHub
- URL: https://github.com/loopmode/scrollbarwidth
- Owner: loopmode
- License: mit
- Created: 2017-06-21T08:37:47.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-08-09T12:10:51.000Z (over 7 years ago)
- Last Synced: 2025-02-25T07:47:26.366Z (about 1 year ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# scrollbarwidth
Extremely simple script for getting the current width of the browser window scrollbar.
If there is no scrollbar when invoked, `0` is returned.
### Installation
# using npm
npm install @loopmode/scrollbarwidth --save
# using yarn
yarn add @loopmode/scrollbarwidth
### Usage
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](https://github.com/loopmode/scrollbarwidth/blob/master/scrollbarwidth.js#L10-L15). It's ridiculously simple.