这个例子是用JS脚本控制并列DIV的高度,通常在DIV布局中,自适应高度一直是比较头疼的问题,一般大都采用背景图、外套DIV、右栏覆盖左 栏......来解决。
现在加了脚本后,简单多了,假如有三个水平并列的DIV,fbox、mbox、sbox,只要在<body>标签中写 入: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
www.projectseven.com
Version: 1.5.0
------------------------------------------------
*/
function P7_colH(){ //v1.5 by PVII-www.projectseven.com
var i,oh,hh,h=0,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
for(i=0;i<dA.length;i++){dA[i].style.height='auto';}for(i=0;i<dA.length;i++){
oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=0;i<dA.length;i++){if(an){
dA[i].style.height=h+'px';}else{P7_eqA(dA[i].id,dA[i].offsetHeight,h);}}if(an){
for(i=0;i<dA.length;i++){hh=dA[i].offsetHeight;if(hh>h){
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-www.projectseven.com
if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!
=document.body.offsetWidth){
P7_colH();}
}
function P7_equalCols(){ //v1.5 by PVII-www.projectseven.com
if(document.getElementById){document.p7eqc=new Array;for(i=0;i<arguments.length;i++){
document.p7eqc[i]=document.getElementById(arguments[i]);}
setInterval("P7_eqT()",10);}
}
function P7_eqA(el,h,ht){ //v1.5 by PVII-www.projectseven.com
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<adT){setTimeout("P7_eqA('"+el+"',"+nh+","+ht+")
",sp);}
}- 用Photoshop给漂亮的烫发MM抠图
- Photoshop透明婚纱抠图大法
- Photoshop:让MM做个“变色龙”
- 用Photoshop来制作一款精美的宝宝照片墙
- Photoshop绝色美女通道抠图法
- 用Photoshop教你打造绚丽光芒效果
巧巧读书:http://www.qqread.com/css/h634115022.html
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
相关专题
- 脚本攻击和防范 (2353篇文章)
- CSS 标签属性 (394次浏览)
- CSS样式表详解 (108次浏览)
- CSS2.0手册(苏沈小雨版) (60次浏览)
- 木子李教程之CSS全攻略 (44次浏览)
- HTML和CSS在Flash中的应用 (0次浏览)
- 通过Dreamweaver学习了解CSS (0次浏览)
- CSS实现文本渐变效果 (0次浏览)
- CSS Hack整理 (0次浏览)
- Photoshop做简单的xhtml+css网页 (0次浏览)
- 面向对象的XHTML与CSS编程 (0次浏览)



