js基础 DIV高度自动调节
js获取浏览器可见区域(不包括标题栏、地址栏、收藏夹栏状态栏等额外区域,仅为页面呈现区域)的高度和宽度
宽度:document.documentElement.clientWidth
高度:document.documentElement.clientHeight
文档类型:XHTML1.0
浏览器:ALL
然后就是获取区块的高度
function
AdjustColumnsHeight() {
var
mainCol = window.document.getElementById(
'MainColumn'
);
var
leftCol = window.document.getElementById(
'MainLeft'
);
var
rightCol = window.document.getElementById(
'MainRight'
);
var
hMainCol = mainCol .offsetHeight;
var
hLeftCol = leftCol.offsetHeight;
var
hRightCol = rightCol.offsetHeight;
var
maxHeight = Math.max( hMainCol , Math.max(hLeftCol, hRightCol));
mainCol.style.height = maxHeight +
'px'
;
leftCol.style.height = maxHeight +
'px'
;
rightCol.style.height = maxHeight +
'px'
;
}
然后就是加以计算 下面是我写的仅供参考 一秒换挡。。 很基础的东西 扎实一点吧
function heighta(){
var a =document.documentElement.clientHeight;
var ac21 =window.document.getElementById("ac21");
var ac22 =window.document.getElementById("ac22");
var ac23 =window.document.getElementById("ac23");
var ac24 =window.document.getElementById("ac24");
var top =window.document.getElementById("top_nav");
var ht = top.offsetHeight;
var bottom_nav =window.document.getElementById("bottom_nav");
var hb = bottom_nav.offsetHeight;
var res=parseInt(a-ht-hb)/2;
ac21.style.height=res+"px";
ac22.style.height=res+"px";
ac23.style.height=res+"px";
ac24.style.height=res+"px";
window.setTimeout("heighta()",1000);
}
window.onload=heighta;