Last active
December 10, 2015 14:08
-
-
Save snahor/4446092 to your computer and use it in GitHub Desktop.
Get scrollbars dimensions. Taken from http://stackoverflow.com/a/8221501/94746
This file contains 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 getScrollBarDimensions() { | |
var elm = document.documentElement.offsetHeight ? document.documentElement : document.body, | |
curX = elm.clientWidth, | |
curY = elm.clientHeight, | |
hasScrollX = elm.scrollWidth > curX, | |
hasScrollY = elm.scrollHeight > curY, | |
prev = elm.style.overflow, | |
r = { vertical: 0, horizontal: 0 }; | |
if ( !hasScrollY && !hasScrollX ) | |
return r; | |
elm.style.overflow = "hidden"; | |
if ( hasScrollY ) | |
r.vertical = elm.clientWidth - curX; | |
if ( hasScrollX ) | |
r.horizontal = elm.clientHeight - curY; | |
elm.style.overflow = prev; | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment