Skip to content

Instantly share code, notes, and snippets.

@dingo-d
Last active March 31, 2017 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dingo-d/33e7cf803a4ce02caaa8e0e698ed2bf3 to your computer and use it in GitHub Desktop.
Save dingo-d/33e7cf803a4ce02caaa8e0e698ed2bf3 to your computer and use it in GitHub Desktop.
Neat function that calculates the scrollbar width
function get_scroll_bar_width() {
var $outer = $( '<div>' ).css( {visibility: 'hidden', width: 100, overflow: 'scroll'} ).appendTo( 'body' ),
width_with_scroll = $( '<div>' ).css( {width: '100%'} ).appendTo( $outer ).outerWidth();
$outer.remove();
return 100 - width_with_scroll;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment