Created
March 8, 2013 10:02
-
-
Save blake-simpson/5115461 to your computer and use it in GitHub Desktop.
A JavaScript function that checks the size of the scrollbar for the current browser and adds a class to the body allowing CSS styling. Useful when designing cross-browser for OSX where some browsers have an overlaid 0 width scrollbar and other use 15px+. The function could be modified to add a data attribute with the exact width, if you need mor…
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
// Discovered here then refactored: http://davidwalsh.name/detect-scrollbar-width | |
var checkScrollbarWidth = function() { | |
var $body = $("body"), | |
$div = $('<div class="scrollbar-measure">'), | |
scrollbarWidth; | |
$div.appendTo( $body ); | |
scrollbarWidth = $div[0].offsetWidth - $div[0].clientWidth; | |
$div.remove(); | |
$body.addClass( scrollbarWidth > 0 ? "has-scrollbar" : "no-scrollbar" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment