Reputation: 505
I have a page with big count of divs such as:
<div class="post">
<table>
<tr> <td><%= post.title %> </td> </tr>
<tr><td colspan="4"><iframe width="370" height="210"
src= "<%= post.url %>" frameborder="0" allowfullscreen></iframe></td> </tr>
</table>
</div>
How can I add lazy loading to this page?
I used jquery-lazyload-any.
I place js to /vendor/assets/javascripts
And to /app/assets/javascripts/application.js add this code
//= require jquery.lazyload-any
function load(img)
{
img.fadeOut(0, function() {
img.fadeIn(1000);
});
}
$('.post').lazyload({load: load});
But nothing happend
Upvotes: 0
Views: 883
Reputation: 505
I found this js https://github.com/ressio/lazy-load-xt#support-video-tag
And put in application.html.erb
<%= javascript_include_tag('jquery.lazyloadxt.extra.js') %>
And this to config/initializer/assets.rb
Rails.application.config.assets.precompile += %w( jquery.lazyloadxt.extra.js )
Upvotes: 1