SOURCE

var scrollbarWidth=function () {  

      var w1, w2, outer,inner;
      outer = document.createElement('div');
      inner = document.createElement('div');
      outer.appendChild(inner);
      
      outer.style.display = 'block';
      outer.style.position = 'absolute';
      outer.style.width = '50px';
      outer.style.height = '50px';
      outer.style.overflow = 'hidden';
      
      inner.style.height = '100px';
      inner.style.width = 'auto';
      
      document.body.appendChild(outer);  
      
      w1 = inner.offsetWidth;  
      outer.style.overflow = 'scroll';  
  
      w2 = inner.offsetWidth;  
  
      if (w1 === w2) {  
        w2 = outer.clientWidth;  
      }  
  
      document.body.removeChild(outer);
  
      return w1 - w2;  
    }

var w=scrollbarWidth();
console.log(w)

console 命令行工具 X clear

                    
>
console