jQuery - Animate然后隐藏

时间:2015-07-29 09:16:09

标签: jquery

在jQuery中,我如何为元素设置动画然后隐藏它?

jsFiddle

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

2 个答案:

答案 0 :(得分:1)

使用jQuery' .animate()回调函数。

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

答案 1 :(得分:0)

使用jquerys animate函数的完整参数

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

希望这有帮助