$(document).height()与$(window).height()区别

$(window).height()代表了当前可见区域的大小,而$(document).height()则代表了整个文档的高度,可视具体情况使用.

注意当浏览器窗口大小改变时(如最大化或拉大窗口后) $(window).height() 随之改变,但是$(document).height()是不变的。

$(window).width(),$(window).height() 不断调整窗口的大小,就会弹出不同的值,这说明这个的值表示浏览器窗口可见部分的高度,不包括状态栏和菜单栏等,只包括显示网页内容的部分,也就是上面说的浏览器客户区

$(document).scrollTop() 获取垂直滚动的距离 即当前滚动的地方的窗口顶端到整个页面顶端的距离
$(document).scrollLeft() 这是获取水平滚动条的距离
要获取顶端 只需要获取到scrollTop()==0的时候 就是顶端了

要获取底端 只要获取scrollTop()>=$(document).height()-$(window).height() 就可以知道已经滚动到底端了

 

$(document).height() //是获取整个页面的高度
$(window).height() //是获取当前 也就是你浏览器所能看到的页面的那部分的高度 这个大小在你缩放浏览器窗口大小时 会改变 与document是不一样的 根据英文应该也能理解吧

自己做个实验就知道了
$(document).scroll(function(){
$("#lb").text($(document).scrollTop());
})
<span id="lb" style="top:100px;left:100px;position:fixed;"></span><!--一个固定的span标记 滚动时方便查看-->

 

<!DOCTYPE html> 
<html> 
<head> 
<meta charset=" utf-8"> 
<meta name="author" content="http://www.softwhy.com/" /> 
<title>蚂蚁部落</title>
<script type="text/javascript" src="http://huodong.178.com/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">  
$(document).ready(function(){
  $("#bt").click(function(){
    alert($(window).width()+","+$(window).height());
  })
})
</script>  
</head>  
<body>
<input type="button" id="bt" value="查看效果"/>
</body>  
</html>

 

 

原文地址:https://www.cnblogs.com/as3lib/p/5039764.html