mirror of
https://github.com/glitch-soc/mastodon.git
synced 2025-12-22 14:58:16 +00:00
20 lines
481 B
TypeScript
20 lines
481 B
TypeScript
import { isMobile } from '../is_mobile';
|
|
|
|
export const getScrollbarWidth = () => {
|
|
if (isMobile(window.innerWidth)) {
|
|
return 0;
|
|
}
|
|
const outer = document.createElement('div');
|
|
outer.style.visibility = 'hidden';
|
|
outer.style.overflow = 'scroll';
|
|
document.body.appendChild(outer);
|
|
|
|
const inner = document.createElement('div');
|
|
outer.appendChild(inner);
|
|
|
|
const scrollbarWidth = outer.offsetWidth - inner.offsetWidth;
|
|
outer.remove();
|
|
|
|
return scrollbarWidth;
|
|
};
|