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
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>瀑布流</title> <style type="text/css"> *{ margin: 0; padding: 0; } ul{ list-style: none; } .root{ width: 1000px; border: 2px solid gold; margin: 30px auto; overflow: hidden;
} .root ul{ width: 240px; border: 1px solid seagreen; float: left; color: white; margin: 4px; text-align: center; font-size: 90px; } </style> </head> <body> <div class="root"> <ul></ul> <ul></ul> <ul></ul> <ul></ul> </div> </body> </html> <script type="text/javascript"> var ulArray = document.querySelectorAll("ul"); function randomNum(min, max){ return Math.floor(Math.random() * (max - min + 1) + min); } function randomColor(){ var red = randomNum(0, 255); var green = randomNum(0, 255); var blue = randomNum(0, 255); return "rgb("+ red + "," + green + "," + blue + ")"; } for(var i = 0; i < 50; i++){ var li = document.createElement("li"); li.innerHTML = i + 1; li.style.backgroundColor = randomColor(); var height = randomNum(100, 500); li.style.lineHeight = height + "px"; li.style.height = height + "px"; var index = 0; for(var j = 1; j < ulArray.length; j++){ if(ulArray[index].offsetHeight > ulArray[j].offsetHeight){ index = j; } } ulArray[index].appendChild(li); } </script>
|