Obtain the absolutely accurate width of the scroll bar.

Source: Internet
Author: User

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 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.