简体   繁体   English

如何按顺序切换jQuery函数?

[英]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. jQuery的animate接受一个回调函数,该动画一旦完成就执行,这意味着您可以执行以下操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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