Jump to content
GreenSock

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

Animations not working with gsap utils or modifiers

Go to solution Solved by GreenSock,

Recommended Posts

Hi,
Can anyone help me with the code that I have? The issue that I'm facing is that when i try to snap a container using the following syntax, the animation seems to skip.

{
    x: "+=" + 200,
    modifiers: {
      x: function (x, target) {
        x = gsap.utils.snap(200, parseInt(x));
        return x + "px";
      }
    }
  }

 

I also used the snap plugin to snap the container into place however, the issue still persisted in this case too.

{ x: "-=" + 200, snap: { x: 200 } }

Any help would be greatly appreciated.

See the Pen PoWKPpK by utkarsh-kumar384 (@utkarsh-kumar384) on CodePen

Link to post
Share on other sites

The way you were doing it would cause the snapping to occur on every update. I assume you meant something more like this?: 

See the Pen 71a69517b31493811e64253701e3d4e1?editors=0010 by GreenSock (@GreenSock) on CodePen

 

If it were me, I'd structure things a bit differently so that I could just animate a container div, and I'd track the position in a variable so that the destination is always "clean", meaning it'll work great even if the user clicks "next" 4 times super quickly: 

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

 

It also centralizes your animation code into one place so you can more easily make edits. 

 

Happy tweening!

  • Like 2
Link to post
Share on other sites

@GreenSock Thank you for the help! You exactly got my issue and fixed it and thank you for the optimization for the code. I'll make sure to do "stateful" animations from now on.

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.

×