[英]infinite scroll with masonry and filterrific
I'm trying to use infinite scroll with filterrific results in a masonry object. 我正在尝试在砖石对象中使用具有出色过滤效果的无限滚动。 When the photos reload, they reload in a single-file but I want the results to fill up the whole page, so I don't think the masonry is being reloaded with the infinite scroll. 重新加载照片时,它们会重新加载为单个文件,但我希望结果能填满整个页面,因此我不认为砖石会随着无限滚动而重新加载。
profiles.js.coffee profiles.js.coffee
$(window).on 'scroll', ->
if $('.pagination').length
@url = $('.pagination .next_page').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
$('.pagination').remove()
$('#filterrific_results').append('<div>')
$('#filterrific_results div').last().load @url+' #filterrific_results', ->
if $('.next_page.disabled').length
$('.pagination').remove()
index.js.erb index.js.erb
<% js = escape_javascript(
render(partial: 'profiles/list', locals: { profiles: @profiles })
) %>
$("#filterrific_results").html("<%= js %>");
<% if @profiles.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@profiles) %>');
<% else %>
$('.pagination').remove();
<% end %>
_list.html.haml _list.html.haml
#filterrific_results
%div
= page_entries_info profiles
%br
.feed-jobs.feed-search{class: (profiles.any? && profiles.first.worker?) ? "feedgrid" : "feedlist"}
= render profiles
= will_paginate profiles
:javascript
$(function() {
var $container;
$container = $(".feedgrid");
$container.imagesLoaded(function() {
$container.masonry({
itemSelector: ".item",
columnWidth: 0,
gutterWidth: 0
}).masonry();
});
});
I figured this out on my own. 我自己解决了这个问题。 I copied some of the code from Railscast #114 endless page http://railscasts.com/episodes/114-endless-page-revised . 我从Railscast#114无休止页面http://railscasts.com/episodes/114-endless-page-revised复制了一些代码。 I included the JS code that supposedly eliminated the pagination code, but it didnt work, do I had to make a CSS div as well. 我包括了应该消除分页代码的JS代码,但是它没有用,我是否还必须制作一个CSS div。 There is probably a DRYer way for this. 可能有一种DRYer方式。
index.js.erb index.js.erb
<% js = escape_javascript(render(partial: 'profiles/list', locals: { profiles: @profiles })) %>
$('#filterrific_results').append('<%= js %>');
<% if @profiles.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@profiles) %>');
<% else %>
$('.pagination').remove();
<% end %>
_list.html.haml (this would be index.html.haml, if you don't partial out) _list.html.haml(如果您不偏心,则为index.html.haml)
#filterrific_results
%div.hiding
= page_entries_info profiles
%br
= render profiles
%div.hiding
= will_paginate profiles
fixes.css.scss fixes.css.scss
.hiding{
display:none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.