`
bcyy
  • 浏览: 1823915 次
文章分类
社区版块
存档分类
最新评论

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 ;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics