Jump to content
Search Community

jQuery Click Events Only Fire Once

Fettabachi test
Moderator Tag

Go to solution Solved by Carl,

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

  • Solution

Hi and welcome to the GreenSock forums,

 

Thanks so much for providing the clear and simple demo. Very helpful.

 

I can see how that would have been a little frustrating. Good news, its a simple fix. 

 

When you opened you were setting the nav to have y:0 (which defaults to a px value baked into a css transform matrix)

<div style="transform: translate3d(0px, 0px, 0px);" class="nav_wrap">

However, when you close the menu you tween to y:"-100%" which creates a separate percentage-based translation.

<div style="transform: translate(0%, -100%) translate3d(0px, 0px, 0px);" class="nav_wrap">

so even though you were technically tweening back to y:0 (px value) you still had the nav at y:"-100%" (off screen). Being able to combine px-based and %-based transforms and animate them independently is extremely powerful, but we recommend that when doing the percentage-based translations that you use the xPercent, yPercent properties.

 

http://greensock.com/gsap-1-13-1

 

In short to fix your pen you could just use y:"0%" in your first tween in the menu-toggle click function, but below is the code to use yPercent

 

$('.menu-toggle').on('click',
 function() {
   TweenMax.to(".nav_wrap", .6, {yPercent:0, ease:Power1.easeInOut, force3D:true})
 TweenMax.set(".cd-primary-nav, .info_wrap", {y:20, opacity:0, ease:Power1.easeInOut, force3D:true})
   TweenMax.to(".cd-primary-nav", .3, {delay:.6, y:0, opacity:1, ease:Power1.easeInOut, force3D:true})
   TweenMax.to(".info_wrap", .3, {delay:.6, y:0, opacity:1, ease:Power1.easeInOut, force3D:true});
});


$('._close_menu').on('click',
 function() {
   TweenMax.to(".nav_wrap", .6, {yPercent:-100, ease:Power1.easeInOut, force3D:true});
});

demo: http://codepen.io/anon/pen/PqvpMj?editors=001

 

Also check out Petr Tichy's video: 

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