Last active
November 19, 2015 08:59
-
-
Save Alex1990/af3486075974fa2f76b5 to your computer and use it in GitHub Desktop.
Get the scrollbar 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
| /** | |
| * Get the scorllbar's width. | |
| * Note: This script only works on the default zoom level. | |
| * Ref: https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/js/modal.js#L277-L284 | |
| */ | |
| function scrollbarWidth() { | |
| var scrollDiv = document.createElement('div'); | |
| scrollDiv.style.cssText = 'position:absolute;left:-9999px;width:50px;height:50px;overflow:scroll;'; | |
| document.body.appendChild(scrollDiv); | |
| var width = scrollDiv.offsetWidth - scrollDiv.clientWidth; | |
| document.body.removeChild(scrollDiv); | |
| return width; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment