首页 > 其他 > 详细

简易瀑布流

时间:2015-03-09 18:54:52      阅读:212      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com">
<meta name="copyright" content="智能社 - zhinengshe.com">
<title>智能社 - www.zhinengshe.com</title>
<style>
* { margin:0; padding:0; }
div { width:966px; margin:10px auto; }
ul { float:left; width:300px; margin:0 10px; border:1px solid red; }
li { background:#ccc; list-style:none; margin-bottom:20px; }
</style>
<script>
window.onload=function (){
    var aUl=document.getElementsByTagName(ul);
    var aTmpUl=[];
    for(var i=0;i<aUl.length;i++)
    {
        aTmpUl.push(aUl[i]);
    }
    appendLi();
    function appendLi()
    {
        for(var i=0;i<20;i++)
        {
            var oLi=document.createElement(li);
            oLi.style.height=rnd(100,300)+px;
            oLi.innerHTML=你吃饭了吗?;
            //比较大小获得高度最小的一个
            aTmpUl.sort(function(ul1,ul2){
                return ul1.offsetHeight-ul2.offsetHeight;
            });
            aTmpUl[0].appendChild(oLi);
        }
    };
    window.onscroll=function()
    {
        var scrollHeigt=document.body.scrollHeight;//获取内容的高度,浏览器不同也有差异
        var scrollTop=document.documentElement.scrollTop || document.body.scrollTop;
        var scrllBottom=scrollTop+document.documentElement.clientHeight;
        if(scrllBottom>=scrollHeigt)
        {
            appendLi();
        }
        
    };
    function rnd(n,m)
    {
        return parseInt(Math.random()*(m-n)+n);
    }
    
};

</script>
</head>

<body>
    <div>
        <ul></ul>
        <ul></ul>
        <ul></ul>
    </div>
</body>
</html>

 

简易瀑布流

原文:http://www.cnblogs.com/heboliufengjie/p/4324117.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!