jQuery - Animate then hide

做~自己de王妃 提交于 2021-01-29 06:45:44

问题


In jQuery how can I animate an element then hide it?

jsFiddle

$(".btn-disapear").click(function () {
    var $this = $(this);
    $(this).closest(".panel").animate({
        opacity: 0
    }, 500).slideUp(400);
});

回答1:


Use jQuery's .animate() callback function.

$(".btn-disapear").click(function () {
    var $this = $(this);
    $(this).closest(".panel").animate({
        opacity: 0
    }, 500, function() {
        $(this).hide(); // applies display: none; to the element .panel
    });
});



回答2:


use the complete parameter of jquerys animate function

$(".btn-disapear").click(function () {
    var $this = $(this);
    $(this).closest(".panel").animate({
        opacity: 0
    }, 500, function(){
        $(this).hide(); //alt $(this).slideUp(400);
    });
});

hope this helped



来源:https://stackoverflow.com/questions/31696175/jquery-animate-then-hide

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