菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
35
0

jquery判断是否出现滚动条?

原创
05/13 14:22
阅读数 802

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 // 网页可见区域

发表评论

0/200
35 点赞
0 评论
收藏
为你推荐 换一批