瀏覽器的異同沒有統(tǒng)一的方法獲取縱向或者橫向滾動條的實際寬度
動態(tài)創(chuàng)建dom結(jié)構(gòu)根據(jù)當(dāng)前瀏覽器計算 純在滾動條和不存在滾動條之間的 offsetWidth 差值
const outer = document.createElement('div');
outer.className = 'scrollbar__wrap';
outer.style.visibility = 'hidden';
outer.style.width = '100px';
outer.style.position = 'absolute';
outer.style.top = '-9999px';
document.body.appendChild(outer);
const widthNoScroll = outer.offsetWidth;
outer.style.overflow = 'scroll';
const inner = document.createElement('div');
inner.style.width = '100%';
outer.appendChild(inner);
const widthWithScroll = inner.offsetWidth;
outer.parentNode.removeChild(outer);
return widthNoScroll - widthWithScroll;