Share a JS to take the size of the scroll bar function code, very simple, very practical.
Create a nested node, let the outer node produce scrollbars, and then use Offsetwidth-clientwidth to get the scrollbar width.
Note that in order to avoid page jitter, you can set the outer elements position:absolute and Visibility:hidden
Full code:
functionGetscrollwith () {varWrap = SetAttributes (document.createelement (' div ')), {style: {width:' 200px ', Height:' 200px ', overflow:' Auto ', Position:' Absolute ', Visibility:' Hidden ' } }) varInner = setattributes (document.createelement (' div ')), {style: {width:' 100px ', Height:' 2000px '}}) Document.body.appendChild (wrap); Wrap.appendchild (inner); varW = wrap.offsetwidth-wrap.clientwidth; document.body.removeChild (wrap); Wrap=NULL; inner=NULL; returnW;} Www.jbxue.comfunctionSetAttributes (elem,opts) { for(varKeyinchopts) { if(typeofOpts[key] = = ' String ') {Elem[key]=Opts[key];}Else{ if(!Elem[key]) {Elem[key]= {}; } SetAttributes (Elem[key],opts[key]); } } returnElem;}