首页 > 代码库 > 简单瀑布流布局(未完成)
简单瀑布流布局(未完成)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> * { margin: 0; padding: 0; } section.wrapper { width: 1260px; margin: 0 auto; } section.wrapper:after { content: ‘‘; display: block; height: 0; clear: both; visibility: hidden; } section.wrapper div.column { float: left; width: 400px; padding: 10px; } .wrapper .waterfall-box { width: 400px; margin-bottom: 10px; background-color: pink; } </style> </head> <body> <section class="wrapper"> <div id="div0" class="column"></div> <div id="div1" class="column"></div> <div id="div2" class="column"></div> </section> <script> var yArr = [10, 10, 10]; const GAP = 10; for (var i = 0; i < 8; i++) { waterfall(); } function waterfall() { var height = parseInt(50 + 200 * Math.random()); var box = document.createElement(‘div‘); box.className = ‘waterfall-box‘; box.style.height = height + ‘px‘; var minY = findMin(yArr); yArr[minY.minIndex] += height + GAP; var div = document.getElementById(‘div‘ + minY.minIndex); div.appendChild(box); function findMin(arr) { var minEle, minIndex; arr.forEach(function (ele, index, arr) { if (minEle === undefined || minEle > ele) { minEle = ele; minIndex = index; } }) return { minEle: minEle, minIndex: minIndex } } } </script> </body> </html>
简单瀑布流布局(未完成)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。