Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
PinkMeNow

Enlarge on hover, reduce on leave

Recommended Posts

What am I doing wrong here. On mouse  hover it should enlarge the text hovered. On mouseleave it should scale back.

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

Link to post
Share on other sites

There were several problems. First, you were using document.getElementsByClassName(".st1") which returns a NodeList (like an Array), but you were treating it like it'd return a single element (by appending .addEventListener(....)). You can't addEventListener() to a NodeList/Array. 

 

Also, you used the wrong selector text. It should simply be "st1", not ".st1" because you're using getElementsByClassName(). I'd recommend switching to document.querySelectorAll() which is more flexible and you can use that selector text (".st1"). 

 

You had logic that'd cause things to grow when the mouse LEAVES them (instead of when it rolls over them). I assume that behavior was inverted, based on what you said in your question. 

 

I wasn't sure if you wanted each piece to animate independently, but here's a fork:

See the Pen 07568569cbe81411ec128eb0a9f542c4?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Does that help? 

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

×