- 论坛徽章:
- 0
|
haitao360312
div自适应窗口高度 - <script type="text/javascript">
- window.onload = windowHeight;//页面载入完毕执行函数
- function windowHeight() {
- var h = document.documentElement.clientHeight;//获取当前窗口可视操作区域高度
- var bodyHeight = document.getElementById("content");//寻找ID为content的对象(也就是你想要自适应高度的对象)
- if (h < 598){//因为前边是获取的当前窗口的可视操作区域的高度 所以当调小窗口的时候 会造成不美观
- h = 598 ;
- bodyHeight.style.height = (h-289) + "px";// +“px” 是解决 firefox不识别 bodyHeight.style.height =h。289数字可以根据需要更改!
- }
- else bodyHeight.style.height = (h-289) + "px";
- }
- setInterval(windowHeight,500)//每半秒执行一次windowHeight函数
- </script>
复制代码 |
|