Jump to content
Search Community

add the class to the element the class is add, but animation don't work

Talha Meer test
Moderator Tag

Recommended Posts

Hi Talha,

 

You're creating the GSAP animations first, when there are no icons with the class of animation and then adding a class afterwards so it won't have any effect.

We usually suggest creating an animation and then using GSAP's control methods to play, reverse or pause the animation on interaction. Good luck!

See the Pen PoqRZOB by GreenSock (@GreenSock) on CodePen

  • Like 1
Link to comment
Share on other sites

  • 6 months later...
On 8/4/2022 at 6:03 PM, Cassie said:

Hi Talha,

 

You're creating the GSAP animations first, when there are no icons with the class of animation and then adding a class afterwards so it won't have any ef

We usually suggest creating an animation and then using GSAP's control methods to play, reverse or pause the animation on interaction. Good luck!
 

 

 

 

Hi Cassie; I am pretty new to this

do you know if it is possible to use this code but instead of transform animation  (i.e. yPercent) we change Position ? (i.e. position: relative to position:absolute) ? 

basically it will be position absolute when mouse is out, then become position:relative when mouse in hovering on. 

Link to comment
Share on other sites

Hi @h-amad and welcome to the GreenSock forums!

 

You can update the position using GSAP, just keep in mind that the position property cannot be animated:

const myElement = document.getElementById("myElement");

myElement.addEventListener("mouseenter", () => {
  gsap.set(myElement, { position: "relative" });
  /* Then create the animation */
});

Hopefully this helps. If you have more questions please remember to include a minimal demo so we can take a better look at what could be the problem.

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.
×
×
  • Create New...