JS获取body的高度

JavaScript013

JS获取body的高度,第1张

1、document.body.clientWidth//网页可见区域宽

2、document.body.clientHeight//网页可见区域高

3、document.body.offsetWidth//网页可见区域宽(包括边线的宽)

4、document.body.offsetHeight//网页可见区域高(包括边线的高)

5、document.body.scrollWidth//网页正文全文宽

6、window.screen.availHeight//屏幕可用工作区高度

7、window.screen.availWidth//屏幕可用工作区宽度

8、alert($(document.body).outerWidth(true))//浏览器时下窗口文档body的总宽度 包括border padding margin

9、alert($(document.body).width())//浏览器时下窗口文档body的高度

扩展资料:

1、alert($(window).height())//浏览器时下窗口可视区域高度

2、alert($(document).height())//浏览器时下窗口文档的高度

3、alert($(document.body).height())//浏览器时下窗口文档body的高度

4、alert($(document.body).outerHeight(true))//浏览器时下窗口文档body的总高度 包括border padding margin

5、alert($(window).width())//浏览器时下窗口可视区域宽度

6、alert($(document).width())//浏览器时下窗口文档对于象宽度

7、alert($(document).scrollTop())//获取滚动条到顶部的垂直高度

8、alert($(document).scrollLeft())//获取滚动条到左边的垂直宽度

javascript screen对象获取屏幕宽高如alert(screen.height)

availHeight 属性 -- 窗口可以使用的屏幕高度,单位像素

availWidth 属性 -- 窗口可以使用的屏幕宽度,单位像素

colorDepth 属性 -- 用户浏览器表示的颜色位数,通常为32位(每像素的位数)

pixelDepth 属性 -- 用户浏览器表示的颜色位数,通常为32位(每像素的位数)(IE不支持)

height 属性 -- 屏幕的高度,单位像素

width 属性 -- 屏幕的宽度,单位像素

div设置定位,宽度高度设为屏幕一般半即可,至于居中的话可以绝对定位。

<html>

<head>

</head>

<body style="height:400px">

<div id="div1">12312</div>

<script type="text/javascript">

document.getElementById("div1").style.height=document.body.style.height

alert(document.getElementById("div1").style.height)

//如果body,没有设置样式,这个高度就为空

document.getElementById("div1").style.height=document.body.clientHeight

alert(document.getElementById("div1").style.height)

//如果设置了样式,offsetHeight就等于样式的height否则等于clientHeight

document.getElementById("div1").style.height=document.body.offsetHeight

alert(document.getElementById("div1").style.height)

</script>

</body>

</html>