Jump to content
Search Community

hover effect with tweenmax

elenika test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts


my problem is: im trying with the help of triggerTo , when you hover on a block with picture - categories to appear one by one. I'm not very strong in js :( so maybe i do mistake there, because my animation works but in a wrong way, i spent many hours researching but haven't found better solution yet.. maybe you can guide me what is wrong




See the Pen PeobOo by elenikaom (@elenikaom) on CodePen

Link to comment
Share on other sites

Hi and welcome to GSAP :) A few quick issues I noticed before getting into how you can use GSAP to accomplish what you described.


You should omit the opening/closing <html>, entire <head>, and opening closing <body> from your CodePen. CodePen basically is setup in a such a way to assume all the html you provide is within the <body></body>. You did a good job of including your scripts through CodePen's settings and providing the necessary CSS within the editor. You also included duplicate code blocks within your Javascript ... everything within and including


$(document).ready(function() {


OK, with all that said, I've forked your pen and modified a few key things. Namely, removing the use of Timelines and using TweenMax in the over/out functions. Another key thing is that 


var $items = $('.content-text span');


as a selector is targeting all of those elements (within the hovered tile and all other tiles) at once. You only want to target those elements within a tile being hovered/unhovered (over or out). So I moved that selector to be within the scope of the tile being over/out



function over(){
  $items = $(this).find('.content-text span'); //<-- $(this) being the hovered
  TweenMax.staggerTo($items, 0.4, {
    y: 0,
    autoAlpha: 1,
    ease: Power4.easeInOut
  }, 0.1);


You'll notice that the initial hover is not moving the items from a lower position up. That's because the hover function has them resting at y:0 and the out has them moving down to y:20. So only after `out` runs on each tile will they be in a position to "move" up to y:0. There are a few ways to tackle that, but I went for a simple one ... simply set all to y:20 on page load.


TweenMax.set( $('.content-text span') , {y:20} );


Now the initial hover Tweens them up to y:0. :)


Here is a CodePen showing it all in action


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


Happy Tweening!

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