首页 > 代码库 > 用JS来控制 div的高度随浏览器变化而变化
用JS来控制 div的高度随浏览器变化而变化
<div id="test" style=" border: solid 1px #f00; "></div><script type="text/javascript"><!--//作者:凌陈亮www.lingchenliang.com(QQ:57404811)autodivheight();function autodivheight(){ //函数:获取尺寸 //获取浏览器窗口高度 var winHeight=0; if (window.innerHeight) winHeight = window.innerHeight; else if ((document.body) && (document.body.clientHeight)) winHeight = document.body.clientHeight; //通过深入Document内部对body进行检测,获取浏览器窗口高度 if (document.documentElement && document.documentElement.clientHeight) winHeight = document.documentElement.clientHeight; //DIV高度为浏览器窗口的高度 //document.getElementById("test").style.height= winHeight +"px"; //DIV高度为浏览器窗口高度的一半 document.getElementById("test").style.height= winHeight/2 +"px";}window.onresize=autodivheight; //浏览器窗口发生变化时同时变化DIV高度//--></script>
用JS来控制 div的高度随浏览器变化而变化
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。