简体   繁体   中英

How do I toggle jQuery functions in order?

I have a menu that is animated to slide from the right when clicking an icon. What I'd like to happen is for the menu's container to slide out and then the list to become visible and the reverse (list fade out then container slide away) when toggled. Currently everything happens at once.

This is where I'm at:

j$(".burger").click(function(){
    j$(".thenavigation").animate({width:'toggle'},350);
    j$(".nav ul").toggleClass("navshow");
});


<div class="burger"></div>
<div class="thenavigation">
    <nav class="nav" role="navigation">
        <ul>.....</ul>
    </nav>
</div>

JQuery's animate accepts a callback function which executes once the animation is done, meaning you can do the following.

j$(".burger").click(function(){
    j$(".thenavigation").animate({width:'toggle'},350, function() {
        j$(".nav ul").toggleClass("navshow");
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM