Good day to all. please help, on the site content is uploaded using AJAX. But after loading the animation does not work. This is a animation call:

<script> $(document).ready(function() { $(".box.animated").hover( function() { $(this).addClass('bounce'); // Добавляем класс bounce }, function() { $(this).removeClass('bounce'); // Убираем класс } )}) </script> 

And this is the upload script itself:

  var infinite_scroll = { loading: { img: " <?php echo get_bloginfo('stylesheet_directory') ?>/img/25.gif", }, "nextSelector":".fetch a", "navSelector":".fetch", "itemSelector":".box", "contentSelector":"#boxes" }; jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll ); 
  • Don't bother to chat here. comments can be left in question and - Alexey Shimansky

1 answer 1

I will try to guess.

You add the hover event immediately after building the DOM tree ( $(document).ready() ). At this moment, an element with class="box animated" does not exist in the DOM tree yet.
As a consequence, the event is not assigned to it.

So you need to assign an event to the .box.animated element after it has been loaded into the markup. This can be done through JavaScript . But! It seems to me a cleaner approach - to make animation via CSS :

 .box.animated:hover { /*Тут пишите те стили, которые содержал класс .bounce*/ } 

UPD

If you really want to use the JS tools, then this:

 $(".box.animated").hover( function() { $(this).addClass('bounce'); // Добавляем класс bounce }, function() { $(this).removeClass('bounce'); // Убираем класс } )}) 

It is necessary to execute in ajax request callback, and not in document ready callback.

The $.ajax (If you do not use the promise model), the success field was responsible for this.

 $.ajax({ ... success: function() {/*Тут назначаете свой ховер*/} ... }) 

Hopefully I could explain

UPD 2

I understood, you have not Jikverai adjax, but endless scrolling. Try to assign an event like this:

 $(document).on("mouseenter", ".box.animated", function(e) { $(this).addClass('bounce'); }).on("mouseleave", ".box.animated", function(e){ $(this).removeClass('bounce'); }); 
  • Where did you get the mouseenter type in the hover event? - Pavel Mayorov
  • one
    It's not mine, but JQuery took it :) - Oleg
  • I do not see hover events at all, only the helper of the same name. - Pavel Mayorov
  • I see that since version 1.9 such a feint with ears does not work. I will fix a little answer - Oleg