//需求是,我需要通过浏览器内容可视化的高度来控制div的高度boxheight(); //执行函数function boxheight(){ //函数:获取尺寸 //获取浏览器窗口高度 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高度为浏览器窗口高度除以1.7 document.getElementById("Odiv").style.height= winHeight/1.7 +"px"; var Oul = document.getElementById("Chat-ul").style.height=Math.ceil(winHeight*1); var Odiv = document.getElementById("chatlist").style.height=Math.ceil(winHeight/1.4); if(Oul>Odiv){ //当ul里内容的高大于div的高才显示div的高,小于则不显示 document.getElementById("chatlist").style.height=Math.ceil(winHeight/1.4)+"px"; } } window.onresize=boxheight; //窗口或框架被调整大小时执行
时间: 2024-12-24 11:50:47