mituri

[JS] getWindowScrollBarWidth

Mar 18th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1.  
  2. function getWindowScrollBarWidth() {
  3. var isWindowHasScrollbar = window.innerWidth > document.documentElement.clientWidth;
  4.  
  5. if (isWindowHasScrollbar) {
  6. var $outer = $('<div>').css({visibility: 'hidden', width: 100, overflow: 'scroll'}).appendTo('body');
  7. var widthWithScroll = $('<div>').css({width: '100%'}).appendTo($outer).outerWidth();
  8.  
  9. $outer.remove();
  10. return 100 - widthWithScroll;
  11. } else {
  12. return 0;
  13. }
  14. };
Advertisement
Add Comment
Please, Sign In to add comment