获取各种高度的方法

做了个小实例,对比各种高度 html代码:

<button type="button" id="mybtn1">$(window).height()</button>
<button type="button" id="mybtn2">$(document).height()</button>
<button type="button" id="mybtn3">$(document.body).height()</button>

js代码:

$(function(){
	//打印$(window).height()的值
	$("#mybtn1").on("click",function(event){
		console.log("$(window).height():"+$(window).height());
	});
	
	//打印$(document).height()的值
	$(document).on("click","#mybtn2",function(event){
		console.log("$(document).height():"+$(document).height());
	});
	$("#mybtn3").on("click",function(event){
		console.log("$(document.body).height():"+$(document.body).height());
	});
});

$(window).height(); //浏览器当前窗口可视区域高度

$(document).height(); //浏览器当前窗口文档的高度

$(document.body).height(); //浏览器当前窗口文档body的高度,内容越多,body高度越高,出现滚动条,数值会很大.

转载于:https://my.oschina.net/daladida/blog/724477

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值