jquery获取窗口高度的方法及判断scroll滚动到底部

$(window).height()     获取的是当前可视窗口的高度,也就是用户能看到的窗口的高度,是不变的(在窗口大小不变的前提下)
$(document).height()  获取的是窗口内文档的高度,这个高度随着文档内容的高度改变而改变

专注于为中小企业提供网站设计、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业彰武免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

当窗口滚动条滚到最低端时,$(document).height() == $(window).height() + $(window).scrollTop()。
当窗口内文档高度不足浏览器窗口高度时,$(document).height()返回的是$(window).height()。

$("body").height()   如果body没有border、margin的话,$("body").height()==$(document).height(),但是还是不建议使用这种方式去获取文档内容高度

PS:如果你发现$(window).height()值有问题,返回的不是浏览器窗口的高度,那么看看是不是网页没有加上声明

滚动某个div中内容的情形如下

代码:





$(document).ready(function(){
  $(".btn1").click(function(){
    $("div").scrollTop(100);
  });
  $(".btn2").click(function(){
    alert($("div").scrollTop()+" px");
  });
});




This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.
把 scroll top offset 设置为 100px 获得 scroll top offset

当滚动条滚动到底部时,此时$("div").scrollTop() = 394px   $("div").height()为div的高度200px不变


分享题目:jquery获取窗口高度的方法及判断scroll滚动到底部
文章出自:http://hxwzsj.com/article/ggdhee.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 移动网站建设 广安网站设计 成都网站制作 成都响应式网站建设公司 成都网站建设推广 企业网站设计 LED网站设计方案 成都网站设计 成都企业网站建设 成都定制网站建设 自适应网站设计 成都网站建设 宜宾网站设计 成都网站建设公司 成都网站制作 网站建设方案 营销网站建设 外贸网站设计方案 成都网站建设公司 专业网站设计 成都商城网站制作 网站设计制作报价