Original, But I was impressed with the idea of a similar method, but it was too long, and my notes only recorded the JS script I wrote, and I couldn't find what I saw at the time.ArticleWhat is written in the end (but it can be determined that the article is not written to get the scroll bar width)
/*! * Obtain the vertical scroll bar width of the browser * first create a div that is invisible to the user and has no scroll bar. After obtaining the DIV width, * set the y-axis scroll bar of the DIV to always visible, then retrieve the DIV width * Delete the DIV and return the difference between the front and back widths ** @ return integer vertical scroll bar width */function getscrollwidth () {var noscroll, scroll, odiv = document. createelement ("Div"); odiv.style.css text = "position: absolute; top:-1000px; width: 100px; Height: 100px; overflow: hidden;"; noscroll = document. body. appendchild (odiv ). clientwidth; odiv. style. overflowy = "scroll"; scroll = odiv. clientwidth; document. body. removechild (odiv); Return noscroll-scroll ;}