Skip to content

Instantly share code, notes, and snippets.

@mmousawy
Last active March 16, 2019 00:31
Show Gist options
  • Select an option

  • Save mmousawy/b10ceeb97c31dcd8a308d44bbb3d369d to your computer and use it in GitHub Desktop.

Select an option

Save mmousawy/b10ceeb97c31dcd8a308d44bbb3d369d to your computer and use it in GitHub Desktop.

Revisions

  1. mmousawy revised this gist Mar 16, 2019. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion scrollbarwidth.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,11 @@
    // Easy immediately invoked function expression (IIFE) to find the current scrollbar width in browser
    // Returns a number of scrollbar width in pixels
    const scrollBarWidth = (() => {
    const a = document.createElement('div');
    document.body.appendChild(a).style.overflowY = 'scroll';
    return a.offsetWidth - a.clientWidth;
    const w = a.offsetWidth - a.clientWidth;
    a.remove();
    return w;
    })();

    console.log(scrollBarWidth);
  2. mmousawy created this gist Mar 16, 2019.
    8 changes: 8 additions & 0 deletions scrollbarwidth.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    // Easy immediately invoked function expression (IIFE) to find the current scrollbar width in browser
    const scrollBarWidth = (() => {
    const a = document.createElement('div');
    document.body.appendChild(a).style.overflowY = 'scroll';
    return a.offsetWidth - a.clientWidth;
    })();

    console.log(scrollBarWidth);