Skip to content

Instantly share code, notes, and snippets.

@tytskyi
Created January 24, 2014 18:34
Show Gist options
  • Save tytskyi/8603288 to your computer and use it in GitHub Desktop.
Save tytskyi/8603288 to your computer and use it in GitHub Desktop.
Extend jQuery with `scrollbarWidth` property.
(function ($) {
var scrollDiv = document.createElement("div");
scrollDiv.style.width = "100px";
scrollDiv.style.height = "100px";
scrollDiv.style.position = "absolute";
scrollDiv.style.top = "-9999px";
scrollDiv.style.overflow= "scroll";
document.body.appendChild(scrollDiv);
// number without suffix "px"
$.scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment