首页 > 代码库 > 获取div滚动条的宽度

获取div滚动条的宽度

获取滚动条的宽度:

function getScrollWidth() {    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);    return noScroll-scroll;    }alert(getScrollWidth()); //chrome下是15,其余的为17