Friday, 15 December, 2017 UTC


Another onliner I love, that returns body scrollbar width. If scrollbar is not shown it will return zero (including mobile devices).
function getScrollbarWidth() { return window.innerWidth - document.documentElement.clientWidth; } 
Click on the button to try it yourself:
Get scrollbar width!
Browser support
Tested on:
  • Windows: IE9, IE10, IE11, Edge
  • MacOS: Safari, Firefox, Chrome, Opera
  • iOS: Safari, Chrome
  • Android: Chrome