zoukankan      html  css  js  c++  java
  • 4列——瀑布流布局

    Demo:

    JS Bin

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="anchor" content="who care?" />
    <title></title>
    <style type="text/css">
         #main{width:756px;margin:0 auto;}
         .pin{float:left;padding:15px 0 0 15px;}
         .box{margin-bottom:15px;padding:5px;border:1px solid #ccc;}
         .box img{width:162px;}
    </style>
    <script type="text/javascript">
        window.onload=function(){
            var oData = {'aData':[{'src':'http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110321053.jpg'},{'src':'http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110439099.jpg'},{'src':'http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110408061.jpg'},{'src':'http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110426042.jpg'}]};
            waterFall(oData.aData);
        };
    
    
        function waterFall(arrData){
            window.onscroll = function(){
                var main = document.getElementById('main'),
                aPin = getClassObj(main,'pin'),
                minH = getMinH(aPin),
                minIndex = getIndex(aPin,minH);
                if(checkH(aPin[minIndex])){
                    for (var i = 0; i < arrData.length; i++) {
                        var oBox = document.createElement('div'),
                        oImg = document.createElement('img');
                        oBox.className = 'box';
                        oImg.src = arrData[i].src;
                        oBox.appendChild(oImg);
                        aPin[minIndex].appendChild(oBox);
                    }
                }
            };
        }
    
        function getClassObj(parent,className){
            var obj = parent.getElementsByTagName('*'), arr = [], i;
            for (i = 0; i < obj.length; i++) {
                if(obj[i].className == className){ arr.push(obj[i]); }
            }
            return arr;
        };
    
        function getMinH(pin){
            var colH = [], i;
            for (i = 0; i < 4; i++) { colH[i] = pin[i].scrollHeight; }
            return Math.min.apply(null,colH);
        };
    
        function checkH(minPin){
            var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
            return (minPin.scrollHeight-scrollTop < 400)?true:false;
        }
    
        function getIndex(arr,minH){
            for(var i in arr){ if(arr[i].scrollHeight == minH)return i; }
        }
    </script>
    </head>
    <body>
      <div id="main">
        <div class="pin">
          <div class="box">
            <img src="http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110426042.jpg" alt=""/>
          </div>
        </div>
        <div class="pin">
          <div class="box">
            <img src="http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110439099.jpg" alt=""/>
          </div>
        </div>
        <div class="pin">
          <div class="box">
            <img src="http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110408061.jpg" alt=""/>
          </div>
        </div>
        <div class="pin">
          <div class="box">
            <img src="http://image142-c.poco.cn/mypoco/myphoto/20130524/11/17362751320130524110321053.jpg" alt=""/>
          </div>
        </div>
      </div>
    </body>
    </html>
    View Code
  • 相关阅读:
    转一篇:arp欺骗的原理和防御
    CF1209A Paint the Numbers
    字符串专题之KMP算法
    CF1209B Koala and Lights
    CF1217A Creating a Character
    CF1217B Zmei Gorynich
    各种模板
    开通博客园拉..
    汇编语言程序设计学习笔记(第一遍学习)第4节:汇编就像HTML一样简单
    我也要学C语言第二十章:结构体类型变量,结构体数组
  • 原文地址:https://www.cnblogs.com/slowsoul/p/3096931.html
Copyright © 2011-2022 走看看