Jump to content
GreenSock

slafleche

Switching from a "left" to Translate() animation

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

Hey there,
I've inherited someone else's code at work. They use your plugin and I gotta say, it's very cool. There's still some stuff I can't figure out though... I need to replace an animation that uses the "left" property to a css transition to make it more smooth, but i can't figure out the syntax...

 

(Just to give you some context, the site has a full height menu on the left. When your cursor goes on top of it, the contents of the page shifts to the left with the menu, but the timing isn't the same so we get an overlapping animated effect)

defineOpenCloseAnimation: function() {
            var e = this,
                n = e.$el.width();
            e.openCloseAnimation = TweenMax.fromTo(e.$el, .500, {
                left: -1 * n
            }, {
                left: 0,
                paused: !0,
                ease: Quart.easeOut
            }), $body = $("body"), e.openCloseBodyAnimation = TweenMax.fromTo($body, 0.8, {
                left: 0,
                ease: Quint.easeInOut
            }, {
                left: n,
                paused: !0,
                ease: Quart.easeInOut
            })
        }

Thanks!

Link to comment
Share on other sites

Hi,

 

It's very simple just replace "left" with "x", like this:

defineOpenCloseAnimation: function() {
            var e = this,
                n = e.$el.width();
            e.openCloseAnimation = TweenMax.fromTo(e.$el, .500, {
                x: -1 * n
            }, {
                x: 0,
                paused: !0,
                ease: Quart.easeOut
            }), $body = $("body"), e.openCloseBodyAnimation = TweenMax.fromTo($body, 0.8, {
                x: 0,
                ease: Quint.easeInOut
            }, {
                x: n,
                paused: !0,
                ease: Quart.easeInOut
            })
        }

That should do it.

 

Keep in mind though that x and y work independently of the element's position on the first render, so if the element's initial left is 200px the x value is zero. Also tweening those values doesn't affect document flow.

 

Rodrigo.

Link to comment
Share on other sites

Hi Rodrigo,

Thanks a lot for your reply.

 

I was able to swap out the "left" for "x" for the menu animation, but not for the body. It seems the translation of the body affects the menu with the translation, but not with the left positioning... 

Link to comment
Share on other sites

Hi,

 

Yep, the thing is that CSS transforms don't affect the document's flow so if you change the x value the left value remains unchanged and vice versa.

 

Also I neglect to remember the fact that you could use force3D:true in order to improve performance without changing the rest of your code:

defineOpenCloseAnimation: function() {
            var e = this,
                n = e.$el.width();
            e.openCloseAnimation = TweenMax.fromTo(e.$el, .500, {
                left: -1 * n,
                force3D:true
            }, {
                left: 0,
                paused: !0,
                ease: Quart.easeOut
            }), $body = $("body"), e.openCloseBodyAnimation = TweenMax.fromTo($body, 0.8, {
                left: 0,
                ease: Quint.easeInOut,
                force3D:true
            }, {
                left: n,
                paused: !0,
                ease: Quart.easeInOut
            })
        }

Give that code a shot and let us know how it went.

 

Rodrigo.

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.
×