1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> <title></title> <style> * { padding:0; margin:0; } html { height:100%; } body { height:100%; } img { border:0; } div.wrap { width:100%; margin:0 auto; overflow:hidden; position:relative; background:#DDD; } div.wrap div { width:220px; padding:4px; border:1px solid #000; float:left; } div.wrap div h3 { line-height:35px; } div.wrap div img { width:220px; } div.wrap div p { padding:5px; line-height:20px; } div.wrap div span { color:#F00; } </style> <script> window.onload = function() { waterFall("wrap") } window.onresize = function() { waterFall("wrap") }
function waterFall(element,space,children) { if(!element) return ; space = space || 20 ; children = children || "div" ; var wrap = document.getElementById(element) ; var water = wrap.getElementsByTagName(children) ; var spaceWidth = water[0].offsetWidth ; var wrapWidth = wrap.offsetWidth ; var colNum = Math.floor(wrapWidth/spaceWidth) ; var padding = Math.floor((wrapWidth - colNum*spaceWidth)/(colNum+1)) ; var column = new Array() ; var length = water.length ; var maxHeight = 0 ; for(var i=0;i<colNum;i++) { column[i] = new Array() ; column[i].top = space ; column[i].left = (spaceWidth * i)+padding*(i+1) ; } for(var i=0;i<length;i++) { var index = i+1 ; if(index%colNum==0) { sub = colNum ; } else { sub = index%colNum ; } _this = water ; _this[i].style.position = "absolute" ; _this[i].style.top = column[sub-1].top + "px" ; _this[i].style.left = column[sub-1].left + "px" ; column[sub-1].top += _this[i].offsetHeight + space ; }
for(var i=0;i<colNum;i++) { if(column[i].top > maxHeight) maxHeight = column[i].top ; } wrap.style.height = maxHeight+"px" ; }
</script> </head> <body> <div class="wrap" id="wrap"> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> <div> <h3>瀑布流</h3> <a href="javascript:void(0)" title=""><img src="01.jpg" alt="" title="" /></a> <p>瀑布流瀑布流瀑布流瀑布流瀑布流瀑布流</p> <span>瀑布流瀑布流瀑布流瀑布流</span> </div> </div> </body> </html>
|