LoginSignup
10
11

More than 5 years have passed since last update.

Railsでkaminari+jQueryで無限スクロール

Posted at

AJAXでの@contentsのページングは適宜行ってください。

js
$(window).scroll( function() {
     var pager = $("#read_more");
     var scrollBottom = $(window).scrollTop() + $(window).height();
     if( scrollBottom > pager.offset().top ) {
           if(!$("#read_more").hasClass("displayed")){
               $("#read_more").addClass("displayed");
               $('#read_more').trigger("click");
           }
     }
});
html
<div id="content_area">
  <% @contents.each do |content| %>
    <%= content.title %>
    <%= content.body %>
  <% end %>
</div>
<%= link_to_next_page '@contents', 'もっと見る', id: 'read_mores', remote: true %>
10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11