Jump to content
GreenSock

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

Stop autoplaying mobile menu

Recommended Posts

Hi there,

 

How can i stop the animation opening by default at the beginning but still keeping the toggle feature?

 

Thanks,

 

Phil

See the Pen PPKevJ by phillip_vale (@phillip_vale) on CodePen

Link to comment
Share on other sites

Hey Phillip,

You can follow the approach marked in this post and toggle between .reverse() and .play():

See the Pen adxyXQ?editors=0010 by Zeaklous (@Zeaklous) on CodePen

.

function menuFunction() {
menu.reversed() ? menu.play() : menu.reverse();
};

Just make sure to .reverse() the original timeline :)

  • Like 4
Link to comment
Share on other sites

Hello phillip_vale, and Welcome to the GreenSock Forum

 

You would need to follow the great advice from ZachSaucier above about reversed.

 

And you need to set the paused: true state to your timeline, very important!

 

See the Pen wMZqVg by jonathan (@jonathan) on CodePen


 

var menu = new TimelineMax({
    paused: true // set timeline to a paused state
  })
  .from("#mobmenu", 1, {
    height: 0,
    ease: Power2.easeInOut,
    immediateRendder: false
  })
  .from("#mobicon", 1, {
    rotation: -45,
    ease: Power2.easeInOut,
    immediateRendder: false
  }, 0)
  .reversed(true); // add reversed state at end of timeline

function menuFunction() {
  menu.reversed() ? menu.play() : menu.reverse();
}

Hope this helps! :)

  • Like 3
Link to comment
Share on other sites

Just a little tip if you want to make the code even shorter: 

//works great:
menu.reversed() ? menu.play() : menu.reverse();
//even shorter:
menu.reversed( !menu.reversed() );
  • Like 4
Link to comment
Share on other sites

Awesome, like butter Jack!  :)

  • Like 2
Link to comment
Share on other sites

I don't know - that's over 30 keystrokes and I'm pretty swamped over here. Can we make it a bit shorter?  :P

  • Like 2
Link to comment
Share on other sites

Another tip. If you add reverse() to the end, you don't have to pause it.

var menu = new TimelineMax()
  .from("#mobmenu", 1, {
    height: 0,
    ease: Power2.easeInOut,
    immediateRendder: false
  })
  .from("#mobicon", 1, {
    rotation: -45,
    ease: Power2.easeInOut,
    immediateRendder: false
  }, 0)
  .reverse();

function menuFunction() {
  menu.reversed(!menu.reversed());
}

See the Pen 6d8f73d30fe2dccbcd8fa154adbb8815 by osublake (@osublake) on CodePen

  • Like 2
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.
×