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

 刘管家 发表于 2021年01月25日 javascript  833
刘管家
LV 2 [幼儿]
最后在线:3年前
加入时间:4年前
主帖:20  跟帖:1
<body>
<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>
论坛主帖
20
论坛跟帖
1
在线访客
2
今日主帖
0
今日跟帖
0
今日注册
0
11
http://imap.91kbl.cn/bbs/gentie.html
http://imap.91kbl.cn/bbs/postzan.html
http://imap.91kbl.cn/bbs/postcai.html
http://imap.91kbl.cn/bbs/postshoucang.html
http://imap.91kbl.cn/bbs/gentiezan.html
http://imap.91kbl.cn/bbs/gentiecai.html
http://imap.91kbl.cn/bbs/huifu.html
http://imap.91kbl.cn/bbs/xiugai.html
http://imap.91kbl.cn/bbs/shanchugentie.html
1
XzA=
1
© 2024 自由园 版权所有
Powered by JianYuLunTan
鲁ICP备16000743号
http://imap.91kbl.cn/bbs/feedback.html
http://imap.91kbl.cn/bbs/qiandao.html
http://imap.91kbl.cn/bbs/denglu.html
0
http://imap.91kbl.cn/bbs/adenglu.html
剑鱼论坛