瀑布流

可定制jQuery瀑布流网格布局插件

阿里云

stackgrid_adem 是一款简单且高度可定制的 jQuery 瀑布流网格布局插件。通过该瀑布流网格插件你可以动态添加和删除各种尺寸的图片,定义图片宽度,设置网格的列数,或使用流式布局方式,甚至还可以通过 URL 动态添加图片。

使用方法:

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

也想出现在这里?联系我们
创客主机
  1. <script src="jquery.min.js"></script>
  2. <script src="stackgrid.adem.js"></script>

HTML 结构:

  1. <div id="grid-container">
  2.   <div class="grid-item">...</div>
  3.   <div class="grid-item">...</div>
  4.   <div class="grid-item">...</div>
  5. </div>

初始化插件:

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

  1. // Create a stackgrid object.
  2. var stackgrid = new $.stackgrid;
  3. var options = {
  4.   column_width: 320
  5. };
  6.  
  7. // Wrap the initializer inside window on load to
  8. // make sure to wait until all the grid contents are loaded.
  9. var $window = $(window);
  10. $window.on('load', function(){
  11.  
  12.   // Initialize stackgrid!
  13.   // The first two arguments are for the container selector and the item selector.
  14.   stackgrid.initialize('#grid-container', '.grid-item', options);
  15.  
  16. });

添加新项:

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

重新排列:

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

配置参数:

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

  1. // The values shown here are the default ones.
  2. stackgrid.config = {
  3.  
  4.   // Your column width.
  5.   column_width: 320,
  6.  
  7.   // Adjust spacing in-between grid-items.
  8.   gutter: 20,
  9.  
  10.   // Set this as true to let stackgrid automatically
  11.   // determine the number of columns based on the
  12.   // viewport's width.
  13.   is_fluid: true,
  14.  
  15.   // Set this as true to sort the grid in an vertically optimal way.
  16.   is_optimized: true,
  17.  
  18.   // If is_fluid is false, it will
  19.   // use this as the default number of columns.
  20.   number_of_columns: 4,
  21.  
  22.   // Timeout delay to call the resize complete function.
  23.   resize_delay: 300,
  24.  
  25.   // You can customize when and how each item is moved!
  26.   // Make sure to use jQuery stop() function if you decide to
  27.   // animate it.
  28.   // Where you place the callback determines
  29.   // when the next move operation is called.
  30.   move: function(element, left, top, callback) {
  31.     element.css({
  32.       left: left,
  33.       top: top
  34.     )};
  35.     callback();
  36.   },
  37.  
  38.   // This function is used to scale the container containing
  39.   // the grid-items.
  40.   // The callback function starts the move operations.
  41.   scale: function(element, width, height, callback) {
  42.     element.css({
  43.       height: height,
  44.       width: width
  45.     });
  46.     callback();
  47.   }
  48. };

备注信息:

  • column_width:网格的宽度。
  • gutter:网格之间的间距。
  • is_fluid:是否设置为流式布局。流式布局会使网格自适应页面视区宽度。
  • is_optimized:该选项设置为 true 可以使垂直的网格优化排序。
  • number_of_columns:如果 is_fluid 选项设置为 flase,则使用该选项的值为默认的网格列数。
  • resize_delay:改变尺寸后的延迟时间。
  • move:自定义什么时候以及如何移动网格。
  • scale:该函数用于缩放保存网格的容器。

可定制 jQuery 瀑布流网格布局插件

已有 400 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(1)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!