jQuery+masonry实现瀑布流

  1. 增加jQuery组件 <script src="//cdn.bootcss.com/jquery/2.2.1/jquery.min.js "></script>
  2. 增加 masonry 组件 <script src="https://npmcdn.com/masonry-layout@4.0.0/dist/masonry.pkgd.min.js "></script>
  3. 插入<div class="grid" id="grid">

    <div class="grid-item">

    <img />

    </div>

    </div>

  1. 初始化组件

    var $grid = $('.grid').masonry({

            itemSelector: '.grid-item',

            columnWidth: 228,

        });

        $grid.masonry('layout');

     

  2. 动态载入

function Loading() {

    $.ajax({

        url: "images.html",

        cache: false,

        async: true,

        /*dataType: html,

        global: true,*/

        success: function(html) {

            //隐藏加载动态图标

            //HideLoading();

 

            var $grid = $('.grid').masonry({

                itemSelector: '.grid-item',

                columnWidth: 228,

            });

 

            var $items = $(html).find('.grid-item');

            $grid.append($items)

                // add and lay out newly appended items

                .masonry('appended', $items);

        }

    });

}

 

posted on 2016-04-11 17:26  my4piano  阅读(945)  评论(0编辑  收藏  举报

导航