Jump to content
Search Community

Animated underline, out and in from same side

IslandScott test
Moderator Tag

Recommended Posts

Hi all,

 

i'm trying to create an animated underline for links. I would like the link to start with a line and then on hover the line should disappear to the right and come in from the left. I hope that makes sense, heres what I have so far, any help would be very appreciated.

 

 

Thank you,

 

Scott.

See the Pen WNgBvVM by IslandScott (@IslandScott) on CodePen

Link to comment
Share on other sites

Hi @IslandScott!

 

I've tweaked your pen a bit how I would set it up. When starting out people gravitate to using .fromTo(), but when you've been using GSAP for a while you'll figure out that you hardly need it, because your element is either already at it's end position or start position and thus a simple .from() or .to() while suffice.

 

Also there are a few properties that you are better of not animating, because they aren't really performant on the top of my head these are: width, height, top, bottom, left, right for all these there are transform properties that are just plain better: scale, x, y (and or xPercent, yPercent), so that is how I set up the pen below. scaleX the line to 0 with a transformOrigin. I think I've set the animation to the reverse of what you want, but try playing with the transformOrigin to get it how you want it. I've also commented out the pause, so that it animates on page load, just to easier debug the animation. Hope it helps and happy tweening! 

 

See the Pen PodvZXM?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen

  • Like 4
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...