获取滚动条高度,页面宽度(高度)

本文介绍了使用JavaScript和jQuery获取网页尺寸及滚动条位置的方法,包括窗口可视区域、文档高度、滚动距离等关键属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

常用页面窗口大小获取:

$(window).height() ==>浏览器时下窗口可视区域高度


$(document).height() ==>浏览器时下窗口文档的高度


$(document.body).height()==>浏览器时下窗口文档body的高度


$(document.body).outerHeight(true)==>浏览器时下窗口文档body的总高度 包括border padding margin


$(document).scrollTop()==>获取滚动条到顶部的垂直高度


$(document).scrollLeft() ==>获取滚动条到左边的垂直宽度


document.body.clientWidth==>(网页)可视区域宽度


document.body.clientHeight==>(网页)可视区域高度


document.documentElement.clientWidth==>页面对象宽度(即BODY对象宽度加上Margin宽)


document.documentElement.clientHeight ==> 页面对象高度(即BODY对象高度加上Margin高)


document.body.offsetWidth==>(网页)可视区域宽度(包括边线的宽) 


document.body.offsetHeight==>(网页)可视区域高度(包括边线的宽)


document.body.scrollWidth ==>网页正文全文宽


document.body.scrollHeight ==>网页正文全文高


window.screen.availHeight==>屏幕可用工作区高度


document.body.scrollTOP==>网页被卷去的高(即到顶部的距离,TOP可换成Left)




<script> 

/*

 * 取窗口滚动条高度 
 */
var getScrollTop = function() {
var scrollTop = 0;
if (document.documentElement && document.documentElement.scrollTop) {
scrollTop = document.documentElement.scrollTop;
} else if (document.body) {
scrollTop = document.body.scrollTop;
}

return scrollTop;
}




/*
 * 取窗口可视范围的高度
 */
var getClientHeight = function() {
var clientHeight = 0;
if (document.body.clientHeight && document.documentElement.clientHeight) {
var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.body.clientHeight
: document.documentElement.clientHeight;
}else {
var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight
: document.documentElement.clientHeight;
}
return clientHeight;

}



/* 滚动条滚动事件 */
$(function(){
$(window).scroll(function(){            //scroll()滚动条滚动事件

if(getScrollTop()>getClientHeight()){
//alert('aa');
}
})

}) 



/*
 * 取文档内容实际高度
 */
var getScrollHeight = function() {
return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
}

</script>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值