【问题标题】:Shuffle.js load more datasShuffle.js 加载更多数据
【发布时间】:2015-10-29 12:44:22
【问题描述】:

我使用https://vestride.github.io/Shuffle/ 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

【问题讨论】:

    标签: jquery grid load shuffle


    【解决方案1】:

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

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

    巴勃罗

    【讨论】:

      猜你喜欢
      • 2013-09-06
      • 2021-10-02
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多