Jump to content
Search Community

Add a function and twwen after reverse

CedGrvl test
Moderator Tag

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

Hi There !

 

I have an animation on a menu. There is no problem to start the animation via the burger button and close it with the cross button
In this menu, I obviously have links to sections of the page.

I would have liked the animation to reverse and I could add one or two tween for opacity or something else.

I can also install a set timeout after the reverse of the animation on the menu links but I think there is another solution.

Could you help me?

Sorry I'm learning as much js as gsap, I guess
Thanks You
Ced

 

 

function displayMenu(){

    let socialMenu = document.querySelectorAll('.js-socialMenu li');
    let animateMenu = new TimelineMax({paused: true});

    animateMenu.to("#js-burger", 0.5, {opacity: 0})
                .to(".js-page", 0.5, {opacity: 0})
                .to(".js-menu", 0.5, {x:0})
                .fromTo(".js-nav", 0.5, {x : "-50vw"}, {x: 0})
                .staggerFromTo(".c-menu__item", 0.1, {x: "-30vw"}, {x: 0}, 0.2)
                .fromTo(".js-logoGrvl", 0.5, {x : "-50vw", opacity: 0}, {x: 0, opacity:1})
                .staggerFromTo(".js-iconMenu", 0.5, {x:-200, opacity: 0}, {x: 0,opacity: 1, rotation: "360"}, 0.2)
                .staggerFromTo(socialMenu, 0.5, {y: 60, opacity:0}, {y: 0, opacity: 1}, 0.2)
                .pause();


    // Store burger button menu
    let burger = document.getElementById("js-burger");
    burger.addEventListener('click', function(){
        animateMenu.play();
    });

    // Store cross button
    let cross = document.getElementById('js-cross');
    cross.addEventListener('click', function(){
            animateMenu.reverse();
    });
    

     //Store  Links
     let menuLinks = document.getElementsByClassName("js-menuLinks");
     for (let i = 0; i< menuLinks.length; i++){

        let location = menuLinks[i].name;

         menuLinks[i].addEventListener('click', function(){

            animateMenu.reverse()
            .call(function() {
                window.location = location;
            })

         })
     };


};


displayMenu();

        

 

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