js屏幕自适应浏览器高度

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <style>
	body{
		margin:0;
		padding:0;
	}
  </style>
 </head>
 <body>
	<div id="test" style=" background:#999;"></div>
 </body>
</html>
<script type="text/javascript">
	autoheight();
	function autoheight(){
		var winHeight=0;
		if (window.innerHeight)
			winHeight = window.innerHeight;
		else if ((document.body) && (document.body.clientHeight))
			winHeight = document.body.clientHeight;
		if (document.documentElement && document.documentElement.clientHeight)
			winHeight = document.documentElement.clientHeight;
		document.getElementById("test").style.height= winHeight +"px";
	}
	window.onresize=autoheight; //浏览器窗口发生变化时同时变化DIV高度
</script>

猜你喜欢

转载自blog.csdn.net/zhangrui_web/article/details/70738263