我从教程http://railscasts.com/episodes/114-endless-page-revised?view=asciicast制作了无尽的页面滚动,它可以工作。
但问题是这个 javascript 运行无休止的页面,每个页面都会分页 - 即使在其他页面上 - 例如,它会尝试对我的消息框进行无休止的分页。
我认为这个脚本非常简单,但我在 javascript 中是 nobie,只是不知道如何告诉脚本只在选定的页面上无限滚动,而不是在项目上的每个 will_paginate 上滚动。我在 JS 文件 $('.paginate) 中看到了这一点 - 告诉脚本为每个分页类运行。
我将非常感谢小费。
ERB 中的 JS:
$('.profile_list').append('<%= j render(@users) %>');
<% if @users.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@users) %>');
<% else %>
$('.pagination').remove();
<% end %>
和 JS i JS 文件:
if ($('.pagination').length) {
$(window).scroll(function() {
var url;
url = $('.pagination .next_page').attr('href');
if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
//$('.pagination').text('Fetching more products...')
$.getScript(url)