Answer the question
In order to leave comments, you need to log in
How to combine Masonry + ajax + infinitescroll?
I am using Masonry to display user cards. The problem is that when I use user filter with AJAX, js masonry doesn't fire, cards are output in 1 column. As I understand it, there is a conflict with the escape_javascript render. Tried disabling turbolinks, didn't help.
var $container = $('#masonry-container');
$container.empty();
$container.append("<%= escape_javascript render @users %>");
<div class="col-md-9">
<div id="masonry-container" class="transitions-enabled infinite-scroll clearfix centered content">
<div id="filter">
<%= render @users %>
</div>
</div>
<div class="span7 text-center"><%= will_paginate %></div>
</div>
$(document).ready(function(){
var $container = $('#masonry-container');
$container.imagesLoaded(function(){
$container.masonry({
itemSelector: '.box',
columnWidth: function( containerWidth ) {
return containerWidth / 20;
},
gutterWidth: 5,
isAnimated: !Modernizr.csstransitions
});
});
Answer the question
In order to leave comments, you need to log in
Yes, Masonry had to be called again.
Here's what I added and it worked.
$( document ).ajaxComplete(function() {
$container.masonry('reloadItems').masonry();
});
Where is the conflict?
Maybe you need to call the function after the elements are added again?
For example, in js.erb, like:
$container.masonry({
itemSelector: '.box',
columnWidth: function( containerWidth ) {
return containerWidth / 20;
},
gutterWidth: 5,
isAnimated: !Modernizr.csstransitions
});
imagesLoaded()
? Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question