Getting the Scrollbar Width

I've been asked a few times if Dimensions would provide a method for getting the scrollbar width. In Dimensions 1.0 I created an internal method for finding the scrollbar width to hack around some browser limitations. I eventually found other ways around those limitations and that code is no longer in Dimensions. I know that in some unusual cases it can be useful, so I want to go ahead and provide that code as one of my jQuery snippets. It is just a single method added to the jQuery namespace called getScrollbarWidth.

  1. $.getScrollbarWidth();

Here is an example of it and here is the small script.

3 Responses to “Getting the Scrollbar Width”

  1. Aleksandr Sugard Says:

    In IE 7.0 your example shows no scroll and text says that "The scrollbar width is 0" =)

  2. Brandon Aaron Says:

    Thanks Aleksandr. My original need for the scrollbar width was not in IE. Silly me ... I forgot about that. After trying a few things I had to end up using a textarea to get the scrollbar width in IE. I've updated the snippet and example. :)

  3. N. Can KIRIK Says:

    intelligent way to get the width. nice job.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>