Skip to content

Instantly share code, notes, and snippets.

@vadimbogomazov
Last active October 17, 2019 17:56
Show Gist options
  • Save vadimbogomazov/3718dea866e166092c5b6eb406f25baa to your computer and use it in GitHub Desktop.
Save vadimbogomazov/3718dea866e166092c5b6eb406f25baa to your computer and use it in GitHub Desktop.
Get browser scrollbar width
/**
* Get browser scrollbar width
* @return {Number}
*/
export const getScrollbarWidth = () => {
const div = document.createElement('div');
div.style.cssText = `
height: 100px;
overflow: scroll;
position: absolute;
top: -9999px;
width: 100px;
`;
document.body.appendChild(div);
const scrollbarWidth = div.offsetWidth - div.clientWidth;
document.body.removeChild(div);
return scrollbarWidth;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment