您的位置:首页 > 其它

$(window).height() 和 $(document).height()的区别

2017-10-22 00:38 363 查看
先上代码:

function b(){
h = $(window).height();
t = $(document).scrollTop();
if(t > h){
$('#gotop').show();
}else{
$('#gotop').hide();
}
}

$(document).ready(function(e) {
b();
$('#gotop').click(function(){
$(document).scrollTop(0);
})
});

$(window).scroll(function(e){
b();
})


注意:
$(window).height()
$(document).height()
的区别`

$(window).height()
代表了当前可见区域的大小,

$(document).height()
则代表了整个文档的高度,可视具体情况使用.

注意:当浏览器窗口大小改变时(如最大化或拉大窗口后) ,

$(window).height()
随之改变,但是
$(document).height()
是不变的。

在实际使用中是需要比较二者大小的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: