Jquery瀑布流网格布局插件

所属分类:UI,媒体-布局,图片展示,图像

 50941  545  查看评论 (10)
分享到微信朋友圈
X
Jquery瀑布流网格布局插件 ie兼容8

使用该瀑布流布局插件之前要先引入jQuery和stackgrid.adem.js文件。

<script src="jquery.min.js"></script>
                <script src="stackgrid.adem.js"></script>                

 HTML结构

该瀑布流网格布局插件使用的是嵌套<div>的HTML结构。

<div id="grid-container">
                  <div class="grid-item">...</div>
                  <div class="grid-item">...</div>
                  <div class="grid-item">...</div>
                </div>   

 初始化插件

在确保所有内容都被加载之后,可以通过下面的方法来初始化该瀑布流网格布局插件。一定要确保所有的内容都被加载,这样可以使stackgrid计算出正确的高度。

// Create a stackgrid object.
                
                var stackgrid = new $.stackgrid;
                
                var options = {
                
                  column_width: 320
                
                };
                
                 
                // Wrap the initializer inside window on load to
                
                // make sure to wait until all the grid contents are loaded.
                
                var $window = $(window);
                
                $window.on('load', function(){
                
                  // Initialize stackgrid!
                
                  // The first two arguments are for the container selector and the item selector.
                
                  stackgrid.initialize('#grid-container', '.grid-item', options);
                
                 
                
                });  

 添加新的网格

该瀑布流网格布局插件允许你动态的添加新的网格。并且这个过程不需要重新绘制所有的网格。

// Create new grid-item.
                
                item = $("<div class=\"grid-item\"> I'm a new grid item. </div>");
                
                // Append it to the grid-container.
                
                item.appendTo("#grid-container");
                
                // *** If the new content has image(s), make sure it's loaded first before appending!
                
                // Append to stackgrid!
                
                stackgrid.append(item);     

 重新排列网格

// Restack the grid to apply your config changes.
                
                stackgrid.config.is_fluid = false;
                
                stackgrid.restack();
                
                 
                
                // Certain changes require you to reset the grid.
                
                // These are changes that affect the dimensions of the grid-item or
                
                // if you remove any of the items.
                
                stackgrid.config.column_width = 400;
                
                stackgrid.reset();
                
                stackgrid.restack();     

 配置参数

下面是该瀑布流网格布局的可用配置参数。

// The values shown here are the default ones.
                
                stackgrid.config = {
                
                 
                
                  // Your column width.
                
                  column_width: 320,
                
                 
                
                  // Adjust spacing in-between grid-items.
                
                  gutter: 20,
                
                 
                
                  // Set this as true to let stackgrid automatically
                
                  // determine the number of columns based on the
                
                  // viewport's width.
                
                  is_fluid: true,
                
                 
                
                  // Set this as true to sort the grid in an vertically optimal way.
                
                  is_optimized: true,
                
                 
                
                  // If is_fluid is false, it will
                
                  // use this as the default number of columns.
                
                  number_of_columns: 4,
                
                 
                
                  // Timeout delay to call the resize complete function.
                
                  resize_delay: 300,
                
                 
                
                  // You can customize when and how each item is moved!
                
                  // Make sure to use jQuery stop() function if you decide to
                
                  // animate it.
                
                  // Where you place the callback determines
                
                  // when the next move operation is called.
                
                  move: function(element, left, top, callback) {
                
                    element.css({
                
                      left: left,
                
                      top: top
                
                    )};
                
                    callback();
                
                  },
                
                 
                
                  // This function is used to scale the container containing
                
                  // the grid-items.
                
                  // The callback function starts the move operations.
                
                  scale: function(element, width, height, callback) {
                
                    element.css({
                
                      height: height,
                
                      width: width
                
                    });
                
                    callback();
                
                  }
                
                };             


column_width:网格的宽度。

gutter:网格之间的间距。

is_fluid:是否设置为流式布局。流式布局会使网格自适应页面视区宽度。

is_optimized:该选项设置为true可以使垂直的网格优化排序。

number_of_columns:如果is_fluid选项设置为flase,则使用该选项的值为默认的网格列数。

resize_delay:改变尺寸后的延迟时间。

move:自定义什么时候以及如何移动网格。

scale:该函数用于缩放保存网格的容器。

相关插件-布局,图片展示,图像

响应式无限滚动瀑布流

响应式无限滚动瀑布流,调整浏览器窗口大小查看效果
  布局
 27440  352

Delta html5模板 Bootstrap 响应式网站前端源码

一个优秀的展示网站为你产品的销售带来更多的亮点,模板简单明了的,只需要简单的更换内容,你的网站就可以直接上线运营。
  布局
 28943  436

响应式完整网站案例+源码

完整的网站前端+源码,各种控件功能齐全,最适合入门者
  布局
 73367  786

网页响应式模板adminEx

简单布局、支持多种终端
  布局
 41944  521

讨论这个项目(10)回答他人问题或分享插件使用方法奖励jQ币 评论用户自律公约

    厌世 0
    2021/4/6 23:34:34
    爱せ刻永恒の平 0
    2017/12/13 17:59:27
    图片点击事件在哪? 回复
    沐皓 0
    2017/6/13 11:02:48
    大白兔Y 0
    2017/4/14 10:56:53

    好虽好,没法直接用,需要剔除若干不需要的东西,反而失掉了简洁,结论:好看不好用,没点JS或CSS基础的,直接建议放弃。

    回复
    pupunew 0
    2017/1/10 10:01:27

    ?漂亮的,但修改程式需要研究一下 著著

    回复
    说破。 0
    2016/1/4 10:01:29

    按照你的步骤来,效果出不来啊!

        蓝天0
        2018/12/6 16:57:26
        同样的 没用 一直报错 流程描述的不清楚
    回复
    ζ 0
    2015/10/8 14:10:05
    月亮上的蝴蝶 0
    2015/7/14 14:07:43
    正是我所需要的,感谢分享 回复
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
😃
  • 😀
  • 😉
  • 😥
  • 😵
  • 😫
  • 😘
  • 😡
  • 👍
  • 🌹
  • 👏
  • 🍺
  • 🍉
  • 🌙
  • 💖
  • 💔
取消回复