Shuffle.js加载更多数据

时间:2015-10-29 12:44:23

标签: jquery grid load shuffle

我使用https://vestride.github.io/Shuffle/ Shuffle

我用一个按钮加载数据。

但是他们不接受网格功能。

我尝试在加载新数据后重新加载grid / Shuffle函数

    var POL = (function( $ ) {

    'use strict';


    var $grid = $('#grid'),
      $filterOptions = $('.filter-options'),
      $sizer = $grid.find('.shuffle__sizer'),


    init = function() {
    setTimeout(function() {
      listen();
      setupFilters();
      setupSorting();
    }, 100);
    $grid.on('loading.shuffle done.shuffle shrink.shuffle shrunk.shuffle 
    filter.shuffle filtered.shuffle sorted.shuffle layout.shuffle', 
    function(evt, shuffle) {
      // Make sure the browser has a console
      if ( window.console && window.console.log && typeof window.console.log === 'function' ) {
        console.log( 'Shuffle:', evt.type );
      }
    });
    $grid.shuffle({
      itemSelector: '.picture-item',
      sizer: $sizer
    });
  },
    setupFilters = function() {
    var $btns = $filterOptions.children();
    $btns.on('click', function() {
      var $this = $(this),
          isActive = $this.hasClass( 'active' ),
          group = isActive ? 'all' : $this.data('group');

      // Hide current label, show current label in title
      if ( !isActive ) {
        $('.filter-options .active').removeClass('active');
      }
      $this.toggleClass('active');
      $grid.shuffle( 'shuffle', group );
    });
    $btns = null;
    },
    setupSorting = function() {
    $('.sort-options').on('change', function() {
      var sort = this.value,
          opts = {};
      if ( sort === 'date-created' ) {
        opts = {
          reverse: true,
          by: function($el) {
            return $el.data('date-created');
          }
        };
      } else if ( sort === 'title' ) {
        opts = {
          by: function($el) {
            return $el.data('title').toLowerCase();
          }
        };
      }
      $grid.shuffle('sort', opts);
    });
    },
  listen = function() {
    var debouncedLayout = $.throttle( 300, function() {
      $grid.shuffle('update');
    });
    $grid.find('img').each(function() {
      var proxyImage;
      if ( this.complete && this.naturalWidth !== undefined ) {
        return;
      }
      proxyImage = new Image();
      $( proxyImage ).on('load', function() {
        $(this).off('load');
        debouncedLayout();
      });
      proxyImage.src = this.src;
    });
    setTimeout(function() {
      debouncedLayout();
    }, 500);
  };   
  return {
    init: init
  };   
    }( jQuery ));
    $(document).on('click','.loadmore',function () {
      $(this).text('Loading...');
         $.ajax({
          url: '/loadmore.php',
          type: 'POST',
          success: function(response){
               if(response){
                    $("#grid").append(response);
                    POL.init();
                  }
                }
       });
    });
    $(document).ready(function() {
    POL.init();
    });

首先加载确定

但点击加载后更多:

After click load more

1 个答案:

答案 0 :(得分:0)

最后,我使用Shuffle附加的方法

$grid.append($item);
$grid.shuffle('appended', $item);

巴勃罗