This repository has been archived on 2024-04-27. You can view files and clone it, but cannot push or open issues or pull requests.
2024-02-27 11:14:03 +03:00
|
|
|
const scrollbarWidth = () => {
|
|
|
|
const outer = document.createElement('div');
|
|
|
|
outer.style.visibility = 'hidden';
|
|
|
|
outer.style.width = '100px';
|
|
|
|
document.body.append(outer);
|
|
|
|
const widthNoScroll = outer.offsetWidth;
|
|
|
|
outer.style.overflow = 'scroll';
|
|
|
|
const inner = document.createElement('div');
|
|
|
|
inner.style.width = '100%';
|
|
|
|
outer.append(inner);
|
|
|
|
const widthWithScroll = inner.offsetWidth;
|
|
|
|
outer.remove();
|
|
|
|
return widthNoScroll - widthWithScroll;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default (getWindowScrollbar = true) => {
|
|
|
|
if (getWindowScrollbar) {
|
|
|
|
if (document.body.clientHeight > window.innerHeight) {
|
|
|
|
return scrollbarWidth();
|
|
|
|
}
|
|
|
|
return 0;
|
2023-06-19 15:01:37 +03:00
|
|
|
}
|
2024-02-27 11:14:03 +03:00
|
|
|
return scrollbarWidth();
|
2023-06-19 15:01:37 +03:00
|
|
|
};
|