使用jquery设置动画,然后隐藏元素
我用它来显示.antwort并对其不透明度应用动画。这个很好用。但是,当再次单击时,会立即隐藏蚂蚁草,而不显示任何动画。我做错了什么使用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({
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;
});
});
参考资料:完美答案。谢谢:)完美的答案。谢谢:)