Jump to content


Hover and out on elements to animate another

Recommended Posts

Hello !


The summary : I would like to create an animation when I hover an element in a list.

My codepen


On hover on the <li>, I get the index of this and I animate the element with the same index in another <div>.

My codepen works but when I hover the elements quickly, the animation is broken.


I found this codepen

See the Pen emxWYb by MAW (@MAW) on CodePen

But this only works for elements in the items hover.


How I can I do a nice animation ?


Thanks a lot ! :)

See the Pen aXBwPQ by anon (@anon) on CodePen

Link to comment
Share on other sites

Hi @gbrl, you were pretty close! For these types of one-on-one interactions, it's often easier just to build a tween to respond rather than build out a timeline.


Here is a CodePen showing what I mean. Also, animating top (and/or left) is perfectly fine, but performance is better if you animate the x/y properties since these use CSS translate.


See the Pen xMRWrz by sgorneau (@sgorneau) on CodePen


Hope this helps!

  • Like 4
Link to comment
Share on other sites



Here's a suggestion for an alternative concept ...


With a quick mouse movement it feels more comfortable - so my feeling, when the 'last / previous' motif runs out of the window upwards.
This example with 'mouseenter' and the 'last' motif remains in its position.


See the Pen GzmQEr by mikeK (@mikeK) on CodePen


Happy tweening ...




  • Like 1
Link to comment
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.