首頁  >  文章  >  web前端  >  腳本控制三行三列自適應高度DIV佈局_經驗交流

腳本控制三行三列自適應高度DIV佈局_經驗交流

WBOY
WBOY原創
2016-05-16 12:09:191735瀏覽

這個例子是用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 
www.projectseven.com Seven Development 
www.projectseven.com Seven Development 
www.projectseven.com .> ---------------------------------------------- 
* / 
function P7_colH(){ //v1.5 by PVII-www.projectseven.com 
var i,oh,hh,h=0,dA=document.p7eqc,an=docqument.pane=docqa; dA&&dA.length){ 
for(i=0;ioh=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.offsetWidthth]); P7_eqT(){ //v1.5 by PVII-www.projectseven.com 
if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw. ();} 

function P7_equalCols(){ //v1.5 by PVII-www.projectseven.com 
if(document.getElementById){document.p7e; 0;idocument.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



[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn