日期:2014-05-16 浏览次数:20695 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>瀑布流布局</title> <style> *{ margin:0px; padding:0px;} li{ list-style:none} #div1{ width:760px; height:auto; margin:20px auto;} ul{ width:240px; margin:5px; float:left;} </style> </head> <body> <div id="div1"> <ul> <li> <img src="img/1.jpg" /> </li> <li> <img src="img/2.jpg" /> </li> <li> <img src="img/3.jpg" /> </li> </ul> <ul> <li> <img src="img/4.jpg" /> </li> <li> <img src="img/5.jpg" /> </li> <li> <img src="img/6.jpg" /> </li> </ul> <ul> <li> <img src="img/7.jpg" /> </li> <li> <img src="img/8.jpg" /> </li> <li> <img src="img/9.jpg" /> </li> </ul> </div> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>定位的瀑布流</title> <style> *{ margin:0px; padding:0px;} li{ list-style:none} #div1{ width:760px; height:auto; margin:20px auto; position:relative;} li{ position:absolute;} </style> <script language="javascript"> window.onload=function(){ var ali = document.getElementsByTagName('li'); var aHeight={L:[],C:[],R:[]}; for(var i = 0;i<ali.length;i++){ var iNow=i%3; switch(iNow){ case 0: ali[i].style.left='5px'; aHeight.L.push(ali[i].offsetHeight); var step=Math.floor(i/3); if(!step){ ali[i].style.top=0; }else{ var sum=0; for(var j=0;j<step;j++){ sum+=aHeight.L[j]+5; } ali[i].style.top=sum+'px'; } break; case 1: ali[i].style.left='250px'; aHeight.C.push(ali[i].offsetHeight); var step=Math.floor(i/3); if(!step){ ali[i].style.top=0; }else{ var sum=0; for(var j=0;j<step;j++){ sum+=aHeight.C[j]+5; } ali[i].style.top=sum+'px'; } break; case 2: ali[i].style.left='495px'; aHeight.R.push(ali[i].offsetHeight); var step=Math.floor(i/3); if(!step){ ali[i].style.top=0; }else{ var sum=0; for(var j=0;j<step;j++){ sum+=aHeight.R[j]+5; } ali[i].style.top=sum+'px'; } break; } } } </script> </head> <body> <div id="div1"> <ul> <li> <img src="img/1.jpg&