hgnl96 hgnl96 - 7 months ago 19
Javascript Question

Shuffle.js function after Ajax call

I use this library: http://vestride.github.io/Shuffle/, works good, but the the problem I have now is, I have a load more button, for loading more images.

It is made with Ajax, but when I call the function again after the Ajax call, the grid is not updated:

$(document).ajaxComplete(function(){
shuffleGrid();
});


My shuffleGrid function:

shuffleGrid = function(){
var $grid = $('#block .content');

$grid.shuffle({
itemSelector: '.views-row'
});
};

Answer

Problem solved by do this:

$(document).ajaxComplete(function(){
    $('#block .content .views-row:not(.shuffle-item)').each(function() {
        var $newRow = $(this);

        $('#block .content').append($newRow);
        $('#block .content').shuffle('appended', $newRow);  
    });
});
Comments