最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
js实现瀑布流效果(自动生成新的内容)
时间:2017-06-30 编辑:简简单单 来源:一聚教程网
当滚动条接近底部会自动生成新的内容(色块)
效果图:
代码如下:
代码如下 | 复制代码 |
*{list-style: none;} div{overflow: hidden;} ul{float: left;} li{width:300px; margin-bottom:10px;}
function rnd(n,m){ return parseInt(Math.random()*(m-n))+n; } function cl(){ var li = document.createElement('li'); li.style.height=rnd(100,500)+'px'; li.style.background='rgb('+rnd(0,255)+','+rnd(0,255)+','+rnd(0,255)+')'; return li; } window.onload=function(){ var aUl = document.getElementsByTagName('ul'); //alert(aUl.length); function c20(){ for(var i =0;i<20;i++){ var arr =[]; for(varj=0;j arr.push(aUl[j]) } arr.sort(function(n,m){ return n.offsetHeight- m.offsetHeight }); arr[0].appendChild(cl()); } } c20(); window.onscroll=function(){ var arr = []; for (varj=0; j < aUl.length; j++) { arr.push(aUl[j]) } arr.sort(function (n, m) { return n.offsetHeight - m.offsetHeight }); var n = (document.body.scrollTop || document.documentElement.scrollTop) + document.documentElement.clientHeight; if (n > arr[0].offsetHeight) { c20() } } }
|