判断是否有滚动条的方法
function hasScrollbar() {
return document.body.scrollHeight > (window.innerHeight || document.documentElement.clientHeight);
}
一般情况下,使用 document.body.scrollHeight > window.innerHeight 就可以判断。
但是在 IE7,IE8 中 window.innerHeight 为 underfined,所以为了兼容 IE7、IE8,需要使用 document.documentElement.clientHeight 属性计算窗口高度。
document.documentElement.scrollLeft >0 //有水平滚动条
或 document.documentElement.scrollTop>0//有垂直滚动条