Holla, I need to reset the animation when I close menu and open it again. How can I do that? Animation works only the first time when I open menu.
CSSPlugin.defaultTransformPerspective = 600;
TweenMax.staggerFrom('ul#menu li', 1.5, {rotationX:-90, transformOrigin:"50% 0%", ease:Elastic.easeOut}, 0.4);
Here is the code: http://codepen.io/hafsadanguir/pen/qOdaab.
Thanks for help!
Is this the kind of result you were after?
JavaScript:
CSSPlugin.defaultTransformPerspective = 600;
var toggleMenu = $('.menu-toggle');
var logo = $('#logo');
var logotitle = $('#logotitle');
var listItems = $('ul#menu li');
var timeline = new TimelineMax({ paused: true, reversed: true });
timeline.fromTo([logo, logotitle], 0.6, { top: 300 }, { top: -50, ease: Power2.easeInOut });
timeline.staggerFromTo(listItems, 1.2, { autoAlpha: 0, rotationX: -90, transformOrigin: '50% 0%' }, { autoAlpha: 1, rotationX: 0, ease: Elastic.easeOut.config(1, 0.3) }, 0.1, 0.3);
toggleMenu.on('click', function() {
$(this).toggleClass('on');
timeline.reversed() ? timeline.play() : timeline.reverse();
});
A few things have changed so here are the details:
hidden
class so I have removed it from my solution.on
class toggled on the .menu-section
element seemed pretty unnecessary as well. I removed it, but kept the properties defined on the .menu-section
CSS rule.TimelineMax
to operate upon. TimelineMax
(and TimelineLite
) are all about. By in any case, TimelineLite
is about building and managing sequences of TweenLite, TweenMax, TimelineLite, and/or TimelineMax instances and TimelineMax
is an extension of TimelineLite
, adding more power to it.TimelineMax
instance has been initialised, tweens have been added to it and then, upon clicking of the .menu-toggle
button element, this timeline is either played or reversed.timeline.reversed() ? timeline.play() : timeline.reverse();
is basically a shortened, fancy version of an if
condition and it comes to down to personal preference more than anything else, no performance gain or anything that I am aware of. In a normal if
clause, it would have been written like this:
if (timeline.reversed()) { timeline.play(); } else { timeline.reverse(); }
..reversed()
property of timeline
. You would notice that while initialising new TimelineMax(...)
, I set reversed: true
property on it. What it does is that after all the tweens are added to timeline
, it would behave as if timeline
was immediately reversed such that the orientation of the timeline
had been flipped. Read more about it in the TimelineMax
documentation link I shared above..play()
and .reverse()
methods are pretty self-explanatory as they make the timeline
go forwards or backwards respectively.Hope this helps.