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

<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>
posted @ 2020-02-18 14:03  Covenant  阅读(946)  评论(0编辑  收藏  举报

ヾ(≧O≦)〃点我返回顶部嗷~