Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9108097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:43:53+00:00 2026-06-17T02:43:53+00:00

Problem: I have implemented an infinitescroll plugin in my rails app, along with JQuery

  • 0

Problem: I have implemented an infinitescroll plugin in my rails app, along with JQuery Masonry. It works perfectly but I am facing one little problem: starting from the second page, the hover function does not get triggered. This problem is very similar to this post on Stackoverflow. I’m supposed to call my hover function again after the Masonry callback.

My original code:

<script>    
$(function () {
    var $container = $('#container_masonry');

    $container.infinitescroll({
        navSelector: '.pagination'
        nextSelector: '.pagination a',
        itemSelector: '.image_masonry'
        loading: {
        finishedMsg: 'Done loading'
        img: 'http://i.imgur.com/6RMhx.gif'
        }
    },
        // trigger Masonry as a callback
        function(newElements) {
            //hide new items while loading
            var $newElems = $(newElements).css({ opacity: 0 });
            //images must be loaded completely before adding to layout
            $newElems.imagesLoaded(function(){
                //they are loaded and ready to be showed
                $newElems.animate({ opacity: 1 });
                $container.masonry( 'appended', $newElems, true );  
            });
        }
    );

    $container.imagesLoaded(function(){
        $container.masonry({
        itemSelector: '.image_masonry',
        columnWidth: 10,
        isAnimated: true,
        animationOptions: { duration: 400 },
        isResizable: true,
        isFitWidth: true
        });

        $('.image_masonry').hover(
        function(){
        $('.title',this).fadeIn();
        $('.like_num',this).show();
        var buttonDiv= $(this).children('.button');
        buttonDiv.toggle();
        }, function(){
        $('.title',this).fadeOut();
        $('.like_num',this).hide();
        var buttonDiv= $(this).children('.button');
        buttonDiv.toggle();
        }); 
    });

});
</script>

I should add the following,

        $('.image_masonry').hover(
        function(){
        $('.title',this).fadeIn();
        $('.like_num',this).show();
        var buttonDiv= $(this).children('.button');
        buttonDiv.toggle();
        }, function(){
        $('.title',this).fadeOut();
        $('.like_num',this).hide();
        var buttonDiv= $(this).children('.button');
        buttonDiv.toggle();
        });

to right after,

            $newElems.imagesLoaded(function(){
                //they are loaded and ready to be showed
                $newElems.animate({ opacity: 1 });
                $container.masonry( 'appended', $newElems, true );
                //ADD HOVER FCN HERE

However, simply adding the whole hover function did not work. I’m new to jQuery so I’m not entirely sure, but I need to pass in the related variables along with the function for it to work (got this hint from the similar post. So I should add something like

        $('.image_masonry').hover(
        function(SOME-RELATED-VARIABLES){
        $('.title',this).fadeIn();
        $('.like_num',this).show();
        var buttonDiv= $(this).children('.button');
        buttonDiv.toggle();
        }, function(SOME-RELATED-VARIABLES){
        $('.title',this).fadeOut();
        $('.like_num',this).hide();
        var buttonDiv= $(this).children('.button');
        buttonDiv.toggle();
        });

But I need someone to teach me what I should put in there. I’m struggling because of my lack of familiarity with jQuery. I appreciate your help a lot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:43:54+00:00Added an answer on June 17, 2026 at 2:43 am

    You were missing some commas between rows 5-11. Also if you’re loading external content at a later time, you need to delegate the hover event with on or delegate depending on your version. I added on below.

    $(function () {
      var $container = $('#container_masonry');
    
      $container.infinitescroll({
        navSelector: '.pagination',
        nextSelector: '.pagination a',
        itemSelector: '.image_masonry',
        loading: {
          finishedMsg: 'Done loading',
          img: 'http://i.imgur.com/6RMhx.gif'
        }
      },
      // trigger Masonry as a callback
      function (newElements) {
        //hide new items while loading
        var $newElems = $(newElements).css({
          opacity: 0
        });
        //images must be loaded completely before adding to layout
        $newElems.imagesLoaded(function () {
          //they are loaded and ready to be showed
          $newElems.animate({
            opacity: 1
          });
          $container.masonry('appended', $newElems, true);
        });
      });
    
      $container.imagesLoaded(function () {
        $container.masonry({
          itemSelector: '.image_masonry',
          columnWidth: 10,
          isAnimated: true,
          animationOptions: {
            duration: 400
          },
          isResizable: true,
          isFitWidth: true
        });
    
        $('body').on({
          mouseenter: function () {
            $('.title', this).fadeIn();
            $('.like_num', this).show();
            var buttonDiv = $(this).children('.button');
            buttonDiv.toggle();
          },
          mouseleave: function () {
            $('.title', this).fadeOut();
            $('.like_num', this).hide();
            var buttonDiv = $(this).children('.button');
            buttonDiv.toggle();
          }
        }, '.image_masonry');
      });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented pagination to my data, but the problem is I only have
I have successfully implemented a cel shader using glsl. But my problem is about
I have just implemented WMD for my editor in an ASP.NET app. The problem
I have implemented an jquery datepicker for an input field in html. Problem is,
I have implemented ajax on paging but my problem is when i navigate on
I have implemented simple proxy server using Java NIO channels, but have a problem,
I have a custom navigation implemented but I have a problem. After I pop
I have implemented a class string, similar to std::string one. I have a problem
I have the following tricky problem: I have implemented a (rather complicated) class which
I have a big problem that is I have implemented a scheduler in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.