Skip to content

Instantly share code, notes, and snippets.

@yukulele
Last active August 29, 2015 13:57
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 yukulele/9911462 to your computer and use it in GitHub Desktop.
Save yukulele/9911462 to your computer and use it in GitHub Desktop.
scrollbar width
var scrollBarWidth = (function(){
var html = document.documentElement;
var outer = document.createElement("div");
var inner = document.createElement("div");
outer.style.visibility = "hidden";
outer.style.width = "100px";
outer.style.overflow = "scroll";
outer.appendChild(inner);
html.appendChild(outer);
var outerWidth = outer.offsetWidth;
var innerWidth = inner.offsetWidth;
html.removeChild(outer);
return outerWidth - innerWidth;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment