瀑布流的实现原理与实例
来源:互联网 发布:java io 简介总结 编辑:程序博客网 时间:2024/06/05 07:58
一、原理:
- 计算每一行能够容纳的列数。
- 寻找每列之中所有高度之和的最小列
- 添加新元素至该列
- 循环找,直到结束。
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <title></title> <script src="jquery-3.2.1.min.js"></script> <style> div.item { position: absolute; width: 200px; margin: 10px; transition: all 1s; } div#content { position: relative; } .part1 { background-color: yellow; height: 200px; } .part2 { background-color: #006ac1; height: 400px; } .part3 { background-color: blueviolet; height: 300px; } </style> </head> <body> <div id="content"> <div class="item part1">1</div> <div class="item part2">2</div> <div class="item part3">3</div> <div class="item part1">4</div> <div class="item part1">5</div> <div class="item part2">6</div> <div class="item part2">7</div> <div class="item part3">8</div> <div class="item part1">9</div> <div class="item part2">10</div> <div class="item part2">11</div> <div class="item part2">12</div> <div class="item part3">13</div> <div class="item part3">14</div> </div> <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js";></script>; <script> function waterFall() { var widthNum = parseInt($(window).width() / $(".item").outerWidth(true)),//求列数 allHeight = [];//所有高度,一维数组 for(var i = 0; i < widthNum; i++) { allHeight.push(0) }//给每一列的高度设置初始值为0 $(".item").each(function() { var $cur = $(this), indx = 0,//设置最小索引值 minAllHeight = allHeight[0];//设置最小高度值 for(var j = 0; j < allHeight.length; j++) { if(allHeight[j] < minAllHeight) { minAllHeight = allHeight[j]; indx = j; } } $cur.css({ "left": indx * $cur.outerWidth(true), "top": minAllHeight }); allHeight[indx] = minAllHeight + $cur.outerHeight(true);//每一列添加对应高度 }) } waterFall(); $(window).on("resize", function() { waterFall() })//改变浏览器大小,调用函数。 </script> </body></html>
阅读全文
0 0
- 瀑布流的实现原理与实例
- 实例解释瀑布流图的实现原理与方法
- 瀑布流的实现原理
- PinterestLikeAdapterView 瀑布流实现原理
- 瀑布流PinterestLikeAdapterView实现原理
- IOS瀑布流实现原理
- js结合jquery实现的ajax瀑布流加载实例
- 仿瀑布流的实现原理,例PinterestListView,PinterestLikeAdapterView,PinterestLikeAdapterView
- 实现网页中常见的瀑布流原理
- 瀑布流的实现
- 瀑布流的实现
- 瀑布流的实现
- 瀑布流布局的原理及实现
- android瀑布流简单实现原理
- 封装自定义瀑布流,实现原理
- iOS开发之瀑布流的实现(UICollectionView与UIScrollView)
- IOS开发之瀑布流的实现(UICollectionView与UIScrollView)
- Android照片墙瀑布流的实现与思考
- <24>—— Swap Nodes in Pairs
- spark从hdfs上读取文件运行wordcount
- java字符串转换数值类型出现异常赋予默认值
- Vue学习笔记十二
- OJ 2525: JK学院的期中测试
- 瀑布流的实现原理与实例
- 图的输入及其边的记录(邻接表)
- 我来看看
- JCIP阅读基础知识(2、3章)随笔
- jenkins 应用发布
- 邝斌的ACM模板(莫比乌斯反演)
- 选择排序
- Codeforces 851C
- WOJ1170-Sorting