Created
October 24, 2012 15:04
-
-
Save Lukewh/3946615 to your computer and use it in GitHub Desktop.
Get the width / height of the browsers scroll bar
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 getScrollWidth(){ | |
| // Create a div | |
| var scrollEle = document.createElement("div"), | |
| scrollWidth = 0; | |
| // Set it's styling | |
| scrollEle.style.width = "100px"; | |
| scrollEle.style.height = "100px"; | |
| scrollEle.style.overflow = "scroll"; | |
| scrollEle.style.position = "absolute"; | |
| scrollEle.style.top = "-9999px"; | |
| // Append element to the page body | |
| document.body.appendChild(scrollEle); | |
| // Get the width | |
| scrollWidth = scrollEle.offsetWidth - scrollEle.clientWidth; | |
| // Remove the Element | |
| document.body.removeChild(scrollEle); | |
| return scrollWidth; | |
| } | |
| document.write(getScrollWidth()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment