码迷,mamicode.com
首页 > Web开发 > 详细

js设置div高度为浏览器一半

时间:2020-02-18 15:11:46      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:load   ini   function   obj   inner   rip   UNC   ||   ntb   

<body onload="init()">
<div id="test">
 
</div>
</body>
<javascript>
function init() {
var totalHeight = window.innerHeight || document.body.clientHeight
var testObj= document.getElementById(‘test‘)
var halfHeight= totalHeight  / 2
testObj.style.height = halfHeight+ ‘px‘
}
</javascript>

js设置div高度为浏览器一半

标签:load   ini   function   obj   inner   rip   UNC   ||   ntb   

原文地址:https://www.cnblogs.com/xujuntao/p/12325985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!