Animating inline elements with jQuery

前端 未结 6 509
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 08:40

I am trying to show and hide an inline element (eg a span) using jQuery.

If I just use toggle(), it works as expected but if I use toggle(\"slow\") to give it an ani

6条回答
  •  半阙折子戏
    2020-12-14 09:10

    I don't think it is possible like that. The only way I could think to do it would be to animate its opacity between 0 and 1, and, using a callback on the animation, then turn it on or off.

    $('.toggle').click(function() {
        $('.hide:visible').animate(
            {opacity : 0},
            function() { $(this).hide(); }
        );
        $('.hide:hidden')
            .show()
            .animate({opacity : 1})
        ;
    });
    

提交回复
热议问题