码迷,mamicode.com
首页 > Web开发 > 详细

jQuery+masonry实现瀑布流

时间:2016-04-11 18:17:22      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:

  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);

????????}

????});

}

?

技术分享

jQuery+masonry实现瀑布流

标签:

原文地址:http://www.cnblogs.com/my4piano/p/5379233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!