jqury实现的横向排序的瀑布流

html代码(li内容自行填充):

  <div class="content-footer">
        <ul>
            <li>
                
            </li>
             <li>
                
            </li>
	<li>
                
            </li>
</ul> </div></div>

css代码:

.content-footer{
    margin: 0 auto;
    width: 1168px;
    position: relative;
}

.content-footer >ul{
    padding: 0;
    position: relative;
    /*!**栏宽**!*/
    /*-webkit-column-width:374px;*/
    /*-moz-column-width:374px;*/
    /*column-width:374px;*/
    /*!**栏间距**!*/
    /*-webkit-column-gap:15px;*/
    /*-moz-column-gap:15px;*/
    /*column-gap:18px;*/
}

.content-footer >ul >li{

    position: relative;
    display: inline-block;
    text-align: left;
    background: #fff;
    width: 374px;
    border-radius: 10px;
    margin-bottom: 15px;
    float: left;
    margin-right: 22px;

}

.content-footer >ul >li:nth-child(3n+0){
    margin-right: 0;
}

js代码:

var footer_li = $('.content-footer >ul >li');
$.each(footer_li,function (index,item) {
   // console.log(index);
    if(index>2){
      // console.log($(footer_li[index-3]).height());
        layout(footer_li,index,item);
    }


})

function getHeight(footer_li,index) {
    var l_height = $(footer_li[index-3]).height();

    if(index-3>2){
        l_height =l_height+ getHeight(footer_li,index-3)+20;
     //   console.log(getHeight(footer_li,index-3));
    }
    return l_height;
}

function getLeft(index) {
    var left;
    if(index%3==0){
        left=0
    }else if(index%3==1){
        left=374+22;
    }else if(index%3==2){
        left=(374+22)*2;
    }
    return left;
}


function layout(footer_li,index,item) {
    var last_height = getHeight(footer_li,index);
    $(item).css({
        'position':'absolute',
        'left':getLeft(index),
        'top':last_height+15,
        'float':'none'
    });
}

转载请注明原文链接


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值