JS控制div的样式(窗口4:3处理算法)

最简单,直接上代码:

var iHeight = document.getElementById("IndexRightDown_left").offsetHeight;
var iWidth = document.getElementById("IndexRightDown_left").offsetWidth;

if (iWidth > 4 * iHeight / 3){
iTemp = (iWidth - 4 * iHeight / 3) / 2;
document.getElementById("OCXDiv").style.position='relative';
document.getElementById("OCXDiv").style.top = 0;
document.getElementById("OCXDiv").style.left= iTemp;
document.getElementById("OCXDiv").style.width = 4 * iHeight / 3;
document.getElementById("OCXDiv").style.height= iHeight;
}else{
iTemp = (iHeight - 3 * iWidth / 4) / 2;
document.getElementById("OCXDiv").style.position='relative';
document.getElementById("OCXDiv").style.top = 0;
document.getElementById("OCXDiv").style.left= iTemp;
document.getElementById("OCXDiv").style.width = iWidth;
document.getElementById("OCXDiv").style.height= 3 * iWidth / 4 ;
}

posted on 2012-03-16 10:39  java课程设计例子  阅读(156)  评论(0编辑  收藏  举报