jquery获取窗口高度和窗口高度,$(document).height()、$(window).height()
用一句话理解就是:当网页滚动条拉到最低端时,$(document).height() == $(window).height() + $(window).scrollTop()。
当网页高度不足浏览器窗口时$(document).height()返回的是$(window).height()。
不建议使用$("html").height()、$("body").height()这样的高度。
原因:
$("body").height():body可能会有边框,获取的高度会比$(document).height()小;
$("html").height():在不同的浏览器上获取的高度的意义会有差异,说白了就是浏览器不兼容。
$(window).height()值有问题,返回的不是浏览器窗口的高度?
原因:网页没有加上声明。
js获取页面高度和窗口高度
实际应用:设置内容区域合适的高度
//设置内容区域合适高度
var docH = $(document).height(),
winH = $(window).height(),
headerH = $(".header").outerHeight();
footerH = $(".footer").outerHeight();
if(docH<=winH+4){
$("div.container").height(winH-headerH-footerH-50);
}
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号