dghez

Hover animation - let finish the animation on mouseleave

Recommended Posts

Hi everyone, 

in simple words here is what I'm trying to achieve:

  1. Start an infinite animation when the user hover a div
  2. Pause the animation when the user leave, but after the animation is completed.

I recreated a codepen as you can see, when I go out of the svg, the animation goes to the end but after it doesn't start anymore.

 

ps: I tried to add play(0) but it will play once (probably because of the callback onRepeat)

 

 

EDIT:

while posting I had an idea and looks like it works :)
I just remove the onRepeat callback on the mouseEnter in this way:

$("svg").hover(function() {
hoverDog.play();
hoverDog.eventCallback("onRepeat", function(){});
}, function() {
hoverDog.eventCallback("onRepeat", function(){ hoverDog.pause();});
});
  • Like 2

Share this post


Link to post
Share on other sites

Thanks for the demo.

 

I have to congratulate you on a very clever solution!

 

The only thing I would add is that you can just pass in null instead of an empty function.

 

$("svg").hover(function() {
hoverDog.play();
hoverDog.eventCallback("onRepeat", null);
}, function() {
hoverDog.eventCallback("onRepeat", function(){ hoverDog.pause();});
});
Great job!
  • Like 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.