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

来源:互联网 发布:校园网络管理 编辑:程序博客网 时间:2024/04/29 06:44

常用页面窗口大小获取:

$(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>


0 0
原创粉丝点击