• 用jquery写的position瀑布流布局


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            .pin{
                padding: 15px 0 0 15px;position: absolute;
                }
            .box{
                padding: 10px;
                border:1px solid #ccc;}
            .box img{
                100px;
                height:auto;}
        </style>
        <script src="jquery.js"></script>
    </head>
    <body>
    <div id="main">
        <div class="pin">
            <div class="box">
                <img src="img/1.jpg"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/2.jpg"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/44.png"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/4.jpg"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/44.png"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/44.png"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/4.jpg"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/4.jpg"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/44.png"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/4.jpg"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/44.png"/>
            </div>
        </div>
        <div class="pin">
            <div class="box">
                <img src="img/4.jpg"/>
            </div>
        </div>   <div class="pin">
        <div class="box">
            <img src="img/4.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/nav60.png"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/4.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/mazha.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/4.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/nav60.png"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/22.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/4.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/33.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/4.jpg"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/nav60.png"/>
        </div>
    </div>   <div class="pin">
        <div class="box">
            <img src="img/4.jpg"/>
        </div>
    </div>
        <div>
     <script>
         window.onload=function(){
             var screenWidth=$(window).width();
             console.log("屏幕宽度:"+screenWidth);
             var cloumnNum= Math.floor(screenWidth/($('.pin').width())) ;
             console.log(cloumnNum)
             var  cloumnHeight=[];
             for(var i=0;i<cloumnNum;i++){
                 cloumnHeight.push(0)
             }
             console.log(cloumnHeight)
             $("#main .pin").each(function(index){
                var elementHeight=$(this).height();
                 var elementWidth=$(this).width();
                 console.log(index%(cloumnHeight.length))
                $(this).css("left",(index%(cloumnHeight.length))*elementWidth).css("top",(cloumnHeight[index%(cloumnHeight.length)]))
                 cloumnHeight[index%(cloumnHeight.length)]+=elementHeight;
                 console.log(cloumnHeight)
             })
         }
     </script>
    </body>
    </html>
    

      

  • 相关阅读:
    法瑞意游记+攻略 一(巴黎 凡尔赛、荣军院,十二月二十六)
    [转]Exchange Server 2013部署系列之一:部署环境介绍
    [转]在Windows server 2012上部署DPM 2012 SP1 RTM之安装配置
    DinnerNow案例分析
    [转]DPM2012系列之六:在Win7上安装DPM远程管理控制台
    Windows Phone Dev Center Develop
    [转]DPM2012系列之十:备份exchange2010数据库
    [转]DPM2012系列之五:开启最终用户恢复功能
    Windows Phone Dev Center How do I join?
    [转]DPM2012系列之三:浅谈硬件需求
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/6381208.html
Copyright © 2020-2023  润新知