Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3852887
  • 博文数量: 421
  • 博客积分: 685
  • 博客等级: 上将
  • 技术积分: 3670
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-18 14:20
文章分类

全部博文(421)

文章存档

2012年(5)

2011年(52)

2010年(83)

2009年(67)

2008年(65)

2007年(149)

分类: 系统运维

2009-09-30 00:08:23

  这个例子是用JS脚本控制并列DIV的高度,通常在DIV布局中,自适应高度一直是比较头疼的问题,一般大都采用背景图、外套DIV、右栏覆盖左 栏......来解决。现在加了脚本后,简单多了,假如有三个水平并列的DIV,fbox、mbox、sbox,只要在标签中写 入:onload="P7_equalCols('fbox','mbox','sbox')",测试条件:ie5.x、ie6.0、FF1.03、 NS7.2、opera8.01。最终效果。
  JS代码:版权归原作者,仅供学习研究.
  /*
  ------------------------------------------------
  PVII Equal CSS Columns scripts
  Copyright (c) 2005 Project Seven Development
  Version: 1.5.0
  ------------------------------------------------
  */
  function P7_colH(){ //v1.5 by PVII-
  var i,oh,hh,h=0,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
  for(i=0;i  oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=0;i  dA[i].style.height=h+'px';}else{P7_eqA(dA[i].id,dA[i].offsetHeight,h);}}if(an){
  for(i=0;ih){
  dA[i].style.height=(h-(hh-h))+'px';}}}else{document.p7eqa=1;}
  document.p7eqth=document.body.offsetHeight;
  document.p7eqtw=document.body.offsetWidth;}
  }
  function P7_eqT(){ //v1.5 by PVII-
  if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw! =document.body.offsetWidth){
  P7_colH();}
  }
  function P7_equalCols(){ //v1.5 by PVII-
  if(document.getElementById){document.p7eqc=new Array;for(i=0;i  document.p7eqc[i]=document.getElementById(arguments[i]);} setInterval("P7_eqT()",10);}
  }
  function P7_eqA(el,h,ht){ //v1.5 by PVII-
  var sp=10,inc=10,nh=h,g=document.getElementById(el),oh=g.offsetHeight,ch=parseInt(g.style.height) ;
  ch=(ch)?ch:h;var ad=oh-ch,adT=ht-ad;nh+=inc;nh=(nh>adT)?adT:nh;g.style.height=nh+'px';
  oh=g.offsetHeight;if(oh>ht){nh=(ht-(oh-ht));g.style.height=nh+'px';}
  if(nh  }
阅读(6246) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-10-13 17:30:25

您的登录名:xiaomm199_zrfis 会员编号:1653477983