js code to calculate browser scroll bar width

The js code to calculate the width of the browser scroll bar:

function getScrollbarWidth() {
    var noScroll, scroll, oDiv = document.createElement("DIV");
    oDiv.style.cssText = "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);
    var getWidth=noScroll-scroll;
    return getWidth;
}

Guess you like

Origin blog.csdn.net/pinhmin/article/details/128702509