1

I'm trying to delay the animation, for this task i'm adding .startAnimation class after 500 milliseconds for animation.

HTML

<div class="layout">Hover It</div>
<div class="hoverDiv"></div> 

JS

setTimeout(function(){
            $(".layout").addClass('startAnimation');
        }, 500);
$('.hoverDiv').hide();
$('.startAnimation').hover(function(){
    $('.hoverDiv').show();
});

But problem is that hover() does not working with added class .startAnimation however its working with .layout class which is located on the same div. I checked .startAnimation class is adding properly after 500 milliseconds. Can any one guide me regarding this issue that i can fix it. I will appreciate.

Here is reference Demo

Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68

2 Answers2

1

Use event delegation with mouseenter, mouseleave events.

$(document).on('mouseenter mouseleave', '.startAnimation', function(){
    $('.hoverDiv').toggle();
});

DEMO

rrk
  • 15,677
  • 4
  • 29
  • 45
0

Use mouseover event instead of hover. It will work.

$(document).on('mouseover', '.startAnimation', function(){
    $('.hoverDiv').show();
});
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27