I want to move away from jQuery for animation so I have been using GSAP. I am trying to figure out how to fire multiple animations on an element and its children. Basically I want to give the #navicon
a "720 cork" effect which is working fine and a fade/toggle the icon to the children of this #navicon
container which is not working at all.
If I was using jQuery only, I would have probably just add multiple classes as needed and use them to trigger some CSS3 transforms. However, GSAP seems to be really fast.
I have read the GSAP docs pretty thoroughly. And I see how to chain tweens with "timeline" but I am not sure how to fire multiple tweens on different elements based on one event.
Here is my code so far:
var toggleMobiMenu = function() {
$('#navicon').on('click touchstart', function() {
TweenMax.to($(this), 0.5, { rotationY: 720, rotationX: -720 })
.to($(this).find('#open'), 0.5, { opacity: 0 })
.to($(this).find('#closed'), 0.5, { opacity: 1 });
});
}
toggleMobiMenu();
and here is the fiddle of the same. Does anyone know how to tween all these 3 elements at once?
Two problems in your code:
to
ofTweenMax
is a static method but what it returns is an instance ofTweenMax
. Read more about the difference between static and instance methods here and this is basically a language agnostic concept. Since, in this case, the instance does not have ato
method available to it as per the docs, your code breaks.find()
method to find#open
and#close
elements inside#navicon
element when clicked, but as per your HTML structure, there are no such things as#open
and#close
elements. Instead you have#navicon-open
and#navicon-close
elements. Putting them instead of the old ones should fix that.So all in all, your code should look like this:
But if I understand it correctly, what you are really trying to do is to come up with an animation that moves forward or backward i.e. toggles every time the icon is clicked. So I have reworked the code in the snippet below provided you an idea of just that:
Snippet:
Hope this helps.