jQuery delay between animations

时间秒杀一切 提交于 2019-11-28 12:16:21

问题


I have two elements that shouldn't be active at the same time, so when one is toggled I fade the other out, however I would like to be able to fade the open element out and then bring the other one in. Is there a way to do this that isn't a hack?

<script ="text/javascript">

$(function() {
    $('#jlogin').click(function() {
        $('#login').toggle('fast');
        $('#reg').fadeOut('fast');
    });

    $('#jreg').click(function() {
        $('#reg').toggle('fast');
        $('#login').fadeOut('fast');
    });
});

</script>

That is my current script.


回答1:


Look at using the callback mechanism for fadeOut so you can chain the animations. The callback on the animation methods are called after the previous animation is complete.

 <script type="text/javascript">
    $(function() {
        $('#jlogin').click(function() {
           $('#reg').fadeOut('fast', function() {
               $('#login').toggle('fast');
           });
        });
        $('#jreg').click(function() {
            $('#login').fadeOut( 'fast', function() {
                $('#reg').toggle('fast');
            });
        });
     });
</script>


来源:https://stackoverflow.com/questions/951528/jquery-delay-between-animations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!