js實現(xiàn)瀑布流效果(自動生成新的內(nèi)容)
更新時間:2017年03月16日 09:54:17 作者:shangpudxd
本文主要介紹了js實現(xiàn)瀑布流效果:當(dāng)滾動條接近底部會自動生成新的內(nèi)容。具有很好的參考價值。下面跟著小編一起來看下吧
當(dāng)滾動條接近底部會自動生成新的內(nèi)容(色塊)
效果圖:
代碼如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{list-style: none;} div{overflow: hidden;} ul{float: left;} li{width:300px; margin-bottom:10px;} </style> <script> 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(var j=0;j<aUl.length;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 (var j = 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() } } } </script> </head> <body> <div> <ul></ul> <ul></ul> <ul></ul> </div> </body> </html>
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關(guān)文章
javascript學(xué)習(xí)隨筆(編寫瀏覽器腳本 Navigator Scripting )
javascript學(xué)習(xí)隨筆(編寫瀏覽器腳本 Navigator Scripting )...2007-03-03JavaScript——DOM操作——Window.document對象詳解
下面小編就為大家?guī)硪黄狫avaScript——DOM操作——Window.document對象詳解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07javascript實現(xiàn)點擊按鈕讓DIV層彈性移動的方法
這篇文章主要介紹了javascript實現(xiàn)點擊按鈕讓DIV層彈性移動的方法,實例分析了javascript操作div層的操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-02-02微信小程序ajax實現(xiàn)請求服務(wù)器數(shù)據(jù)及模版遍歷數(shù)據(jù)功能示例
這篇文章主要介紹了微信小程序ajax實現(xiàn)請求服務(wù)器數(shù)據(jù)及模版遍歷數(shù)據(jù)功能,結(jié)合實例形式分析了微信小程序ajax調(diào)用及模板wx:for循環(huán)列表渲染相關(guān)操作技巧,需要的朋友可以參考下2017-12-12