网页中的层div,如何根据窗体大小而改变位置?

wh1226 2008-07-05 03:02:48
我的层:

<div id="tree_div" style="width: 209px; height: 405px; display: block; position: absolute;
left: 746px; top: 121px; background-color: #ffffff; filter: alpha(opacity=90)">
<iframe id="tree_iframe" frameborder="0" width="209px" height="400px" scrolling="no">
</iframe>
</div>


我copy来的自适应窗体代码,在<body>里用onresize调用这个方法可以改变table随窗体活动,可是div不变,很郁闷,大家帮我想想办法,最好是直接给我代码.谢谢大家

<script type="text/javascript">

function getWindowWidth2()
{
if (window.self && self.innerWidth)
{
return self.innerWidth;
}
if (document.documentElement && document.documentElement.clientWidth)
{
return document.documentElement.clientWidth;
}
return document.body.clientWidth;

};

function getWindowHeight2()
{
if (window.self && self.innerHeight)
{
return self.innerHeight;
}
if (document.documentElement && document.documentElement.clientHeight)
{
return document.documentElement.clientHeight;
}
return document.body.clientHeight;

};

function wndResize()
{

var cw=getWindowWidth2()-15;
var ch=getWindowHeight2()-130;

maplet.resize(cw,ch);

}

</script>
...全文
345 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
llx993 2012-08-20
  • 打赏
  • 举报
回复
That is right.
[Quote=引用 5 楼 的回复:]
window.onresize=function(){
var div=document.getElementById('div1');
div.style.width=(document.documentElement.scrollWidth-15)+'px';
div.style.height=(document.documentElement.scrollHeight-20)+'px'……
[/Quote]
只是有点伤感 2012-07-25
  • 打赏
  • 举报
回复
window.onresize=function(){
var div=document.getElementById('div1');
div.style.width=(document.documentElement.scrollWidth-15)+'px';
div.style.height=(document.documentElement.scrollHeight-20)+'px';
}
fsx999 2008-07-14
  • 打赏
  • 举报
回复
咱公司论坛里有!!!
拿分来!
brz97 2008-07-05
  • 打赏
  • 举报
回复
另外,div默认自动填充,也就是说,如果楼主没有定义在div的style中定义overflow:hidden;的话,div会自动被里面的内容撑大
所以即使改变大小也是无效的
brz97 2008-07-05
  • 打赏
  • 举报
回复
好像div不支持resize
楼主这样改变div大小

var div=document.getElementById('divid');
div.style.width=(getWindowWidth2()-15)+'px';
div.style.height=(getWindowHeight2()-130)+'px';
jsycsj 2008-07-05
  • 打赏
  • 举报
回复
试试offsetHeight, offsetWidth, offsetLeft, offsetTop呢

7,765

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧