jQuery 如何判断是否存在滚动条? 下面本篇文章就来给大家介绍一下使用 jQuery 判断是否存在滚动条的方法. 有一定的参考价值, 有需要的朋友可以参考一下, 希望对大家有所帮助.
方法 1: 通过判断可视区域是否超过实际高度, 超过则存在滚动条
- if ($(Windows).height() <$(document).height() ) {
- alert('出现滚动条')
- }
说明:
$(Windows).height() : 浏览器窗口可视区域高度
相当于 JS 的 document.documentElement.clientHeight
$(document).height(): 浏览器窗口文档的高度
相当于 JS 的 document.documentElement.offsetHeight
方法 2: 判断 "屏幕可用工作区高度" 是否 大于等于 (>=)"网页可见区域"
- if (Windows.screen.availHeight>= document.body.clientHeight) {
- alert("页面无滚动条")
- } else {
- alert("页面有滚动条")
- }
说明:
Windows.screen.availHeight: 屏幕可用工作区高度
document.body.clientHeight : 网页可见区域
更多 web 开发 https://www.html.cn/ 知识, 请查阅 HTML 中文网 !!
来源: http://www.css88.com/qa/jquery/15941.html