奇怪的问题,关于js+css实现页面内容高度自适应的两种解决方案

本站blog板块 的css.css样式表中,我用以下CSS的语法成功实现了IE/火狐 两种浏览器的内嵌页面,随着页面内容多少自适应问题:

 


淘宝网精品女装
淘宝网女士服装
淘宝网女士内衣
淘宝网入口 (健身减肥产品,汽车装饰,男人装,数码玩意...应有尽有)
淘宝网入口官方网站

 

#tag {width:950px;height:auto!important; min-height:388px; height:auto;overflow:hidden;margin:0 auto;}
#header {width:950px;height:40px;margin:0 auto;}
#page {width:950px;height:auto!important; min-height:388px; height:auto;overflow:hidden;margin:0 auto;background:#ffffff;}
#left{width:295px;height:auto!important; min-height:388px; height:auto;overflow:hidden;float:left;background:url(images/1_10.gif);}
#right{width:655px;height:auto!important; min-height:388px; height:auto;overflow:hidden;margin:0px 0px 0px 0px;float:left;background:#ffffff;}


淘宝网精品女装
淘宝网女士服装
淘宝网女士内衣
淘宝网入口 (健身减肥产品,汽车装饰,男人装,数码玩意...应有尽有)
淘宝网入口官方网站

然而,在本站主页面的main.css中,用了类似以上的CSS语法:height:auto!important;min-height:388px;height:auto;overflow:hidden

却无法实现高度自适应。

 


淘宝网精品女装
淘宝网女士服装
淘宝网女士内衣
淘宝网入口 (健身减肥产品,汽车装饰,男人装,数码玩意...应有尽有)
淘宝网入口官方网站


不得已,用JS的方式实现了高度自适应问题,这样以后我要修改页面内容,则只需要修改item_xxx.html内嵌页面,而不需要像以前一样,去修改JS中的document.writeln中的height参数。

确实方便多了,但有个弊端,这样给网站服务器增加了负载(因为JS要计算内嵌iframe页面的高度),而且,网速不够快的用户,很容易被卡到页面,把当前页面显示为一个空白。

不明白,为什么两种方法实现的效果不一样。

 

下面共享一下本人用JS实现内嵌页面高度自适应功能的代码:
<!--
function AutoHeight(fm_name,fm_id){
     var frm=document.getElementById(fm_id);
     var subWeb=document.frames?document.frames[fm_name].document:frm.contentDocument;
     if (frm != null && subWeb != null){
        frm.style.height = subWeb.documentElement.scrollHeight+ "px" ;
//如需自适应宽高,去除下行的“//”注释即可
//      frm.style.width = subWeb.documentElement.scrollWidth+"px";
     }
}



淘宝网精品女装
淘宝网女士服装
淘宝网女士内衣
淘宝网入口 (健身减肥产品,汽车装饰,男人装,数码玩意...应有尽有)
淘宝网入口官方网站

//-->
document.writeln("<iframe onLoad =/"{AutoHeight('FM_Name','FM_Id');}/" ");
document.writeln("src =/"../item_forU.html/" ");
document.writeln("name =/"FM_Name/" id =/"FM_Id/" width =/"950/" marginwidth =/"0/" marginheight =/"0/" ");
document.writeln("frameborder =/"0/" scrolling =/"no/"><//iframe>")

(PS:做人要厚道,转载请注明出处:http://www.3netgo.com/blog

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值