Skip to content

Instantly share code, notes, and snippets.

@lackneets
Created November 10, 2016 07: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 lackneets/e9f29b2bb87c2d6a6dc54603672e43e3 to your computer and use it in GitHub Desktop.
Save lackneets/e9f29b2bb87c2d6a6dc54603672e43e3 to your computer and use it in GitHub Desktop.
from bootstrap modal
function getScrollbarWidth(){
var scrollDiv = document.createElement('div');
scrollDiv.style.position = 'absolute';
scrollDiv.style.top = '-9999px';
scrollDiv.style.width = '50px';
scrollDiv.style.height = '50px';
scrollDiv.style.overflow= 'scroll';
document.body.appendChild(scrollDiv);
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
return scrollbarWidth;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment