下面就为大家带来一篇jQuery判断是否存在滚动条的简单方法。分享给大家,也给大家做个参考,一起来看看吧。
jquery判断是否出现滚动条?
一、判断可视区域是否超过实际高度,超过一定存在if ($(window).height() < $(document).height() ) {
alert('出现滚动条')
}
使用原生JavaScript的写法if (document.documentElement.clientHeight < document.documentElement.offsetHeight){
alert('出现滚动条')
}
二、屏幕可用工作区高度>=网页可见区域if (window.screen.availHeight >= document.body.clientHeight) {
alert("页面无滚动条")
} else {
alert("页面有滚动条")
}
注:
● $(window).height() // 浏览器窗口可视区域高度
document.documentElement.clientHeight
● $(document).height() // 浏览器窗口文档的高度
document.documentElement.offsetHeight
● window.screen.availHeight // 屏幕可用工作区高度
● document.body.clientHeight // 网页可见区域
本文来自jQuery答疑栏目,欢迎学习!