10
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?