Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jquery设置动画,然后隐藏元素_Jquery_Jquery Animate - Fatal编程技术网

使用jquery设置动画,然后隐藏元素

使用jquery设置动画,然后隐藏元素,jquery,jquery-animate,Jquery,Jquery Animate,我用它来显示.antwort并对其不透明度应用动画。这个很好用。但是,当再次单击时,会立即隐藏蚂蚁草,而不显示任何动画。我做错了什么 jQuery(document).ready(function ($) { $(".frage li").click(function () { if (!$(this).find(".antwort").is(".open")) { $(this).find(".antwort").css({

我用它来显示.antwort并对其不透明度应用动画。这个很好用。但是,当再次单击时,会立即隐藏蚂蚁草,而不显示任何动画。我做错了什么

jQuery(document).ready(function ($) {
    $(".frage li").click(function () {
        if (!$(this).find(".antwort").is(".open")) {
            $(this).find(".antwort").css({
                display: "block"
            });
            $(this).find(".antwort").animate({
                opacity: 1
            }, 1500).addClass('open');
        } else {
            $(this).find(".antwort").animate({
                opacity: 0
            }, 1500).removeClass('open');
            $(this).find(".antwort").css({
                display: "none"
            });
        }
        return false;
    });
});

只需使用
fadeToggle()


只需使用
fadeToggle()


在指定“无显示”之前,应等待动画完成,否则“无显示”将立即生效,并且您将无法看到动画(元素已隐藏)。 使用animate方法的回调函数,如下所示:

jQuery(document).ready(function ($) {
    $(".frage li").click(function () {
        if (!$(this).find(".antwort").is(".open")) {
            $(this).find(".antwort").css({
                display: "block"
            });
            $(this).find(".antwort").animate({
                opacity: 1
            }, 1500).addClass('open');
        } else {
            $(this).find(".antwort").animate({
                opacity: 0
            }, 1500, function() {
               // Animation complete.
               $(this).hide()
            }).removeClass('open');
        }
        return false;
    });
});

参考:

在指定“无显示”之前,应等待动画完成,否则“无显示”将立即生效,您将无法看到动画(元素已隐藏)。 使用animate方法的回调函数,如下所示:

jQuery(document).ready(function ($) {
    $(".frage li").click(function () {
        if (!$(this).find(".antwort").is(".open")) {
            $(this).find(".antwort").css({
                display: "block"
            });
            $(this).find(".antwort").animate({
                opacity: 1
            }, 1500).addClass('open');
        } else {
            $(this).find(".antwort").animate({
                opacity: 0
            }, 1500, function() {
               // Animation complete.
               $(this).hide()
            }).removeClass('open');
        }
        return false;
    });
});

参考资料:

完美答案。谢谢:)完美的答案。谢谢:)