v1.1.0
This commit is contained in:
parent
9f1c82f4d3
commit
f86a91d8d1
10
README.md
10
README.md
|
@ -1,7 +1,17 @@
|
||||||
# get-scrollbar-width
|
# get-scrollbar-width
|
||||||
|
|
||||||
|
Get window scrollbar width (if present):
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import getScrollbarWidth from '@advdominion/get-scrollbar-width';
|
import getScrollbarWidth from '@advdominion/get-scrollbar-width';
|
||||||
|
|
||||||
console.log(getScrollbarWidth());
|
console.log(getScrollbarWidth());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Get system scrollbar width:
|
||||||
|
|
||||||
|
```js
|
||||||
|
import getScrollbarWidth from '@advdominion/get-scrollbar-width';
|
||||||
|
|
||||||
|
console.log(getScrollbarWidth(false));
|
||||||
|
```
|
||||||
|
|
11
index.js
11
index.js
|
@ -1,5 +1,4 @@
|
||||||
export default () => {
|
const scrollbarWidth = () => {
|
||||||
if (document.body.clientHeight > window.innerHeight) {
|
|
||||||
const outer = document.createElement('div');
|
const outer = document.createElement('div');
|
||||||
outer.style.visibility = 'hidden';
|
outer.style.visibility = 'hidden';
|
||||||
outer.style.width = '100px';
|
outer.style.width = '100px';
|
||||||
|
@ -12,6 +11,14 @@ export default () => {
|
||||||
const widthWithScroll = inner.offsetWidth;
|
const widthWithScroll = inner.offsetWidth;
|
||||||
outer.remove();
|
outer.remove();
|
||||||
return widthNoScroll - widthWithScroll;
|
return widthNoScroll - widthWithScroll;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default (getWindowScrollbar = true) => {
|
||||||
|
if (getWindowScrollbar) {
|
||||||
|
if (document.body.clientHeight > window.innerHeight) {
|
||||||
|
return scrollbarWidth();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
return scrollbarWidth();
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@advdominion/get-scrollbar-width",
|
"name": "@advdominion/get-scrollbar-width",
|
||||||
"version": "1.0.0",
|
"version": "1.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
Reference in New Issue