Skip to content

Instantly share code, notes, and snippets.

@olecksamdr
Last active March 18, 2019 11:30
Show Gist options
  • Save olecksamdr/1a7686f5b70c6b1f9d9cb58bab10da7e to your computer and use it in GitHub Desktop.
Save olecksamdr/1a7686f5b70c6b1f9d9cb58bab10da7e to your computer and use it in GitHub Desktop.
export const getScrollbarWidth = () => {
const scrollDiv = document.createElement('div');
scrollDiv.style.cssText = `
position: absolute;
top: -9999px;
width: 50px;
height: 50px;
overflow: scroll
`;
document.body.appendChild(scrollDiv);
const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
return scrollbarWidth;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment