标签:
1、此方法检验成功
function getScrollbarWidth() {
var oP = document.createElement(‘p‘),
styles = {
width: ‘100px‘,
height: ‘100px‘
}, i, clientWidth1, clientWidth2, scrollbarWidth;
for (i in styles) oP.style[i] = styles[i];
document.body.appendChild(oP);
clientWidth1 = oP.clientWidth;
oP.style.overflowY = ‘scroll‘;
clientWidth2 = oP.clientWidth;
scrollbarWidth = clientWidth1 - clientWidth2;
oP.parentNode.removeChild(oP);
return scrollbarWidth;
}
2、和一原理差不多。
function getScrollbarWidth() {
var oP = document.createElement(‘p‘),
styles = {
width: ‘100px‘,
height: ‘100px‘,
overflowY: ‘scroll‘
}, i, scrollbarWidth;
for (i in styles) oP.style[i] = styles[i];
document.body.appendChild(oP);
scrollbarWidth = oP.offsetWidth - oP.clientWidth;
oP.parentNode.removeChild(oP);
return scrollbarWidth;
}
标签:
原文地址:http://www.cnblogs.com/huaan011/p/4800542.html