Last active
April 21, 2018 06:34
-
-
Save tranlehaiquan/da3bb0ee8bc594c4acaa1e73d6b3a897 to your computer and use it in GitHub Desktop.
Get scroll bar width
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// function from | |
// https://evilmartians.com/chronicles/scroll-to-the-future-modern-javascript-css-scrolling-implementations | |
function getScrollBarWidth() { | |
const outer = document.createElement('div'); | |
const inner = document.createElement('div'); | |
outer.style.overflow = 'scroll'; | |
outer.appendChild(inner); | |
document.body.appendChild(outer); | |
const scrollBarWidth = outer.offsetWidth - inner.offsetWidth; | |
document.body.removeChild(outer); | |
return scrollBarWidth; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment