简体   繁体   English

运行动画然后删除元素

[英]run animation then remove element

I am tring to run a simple animation then remove the div since it lies over some buttons so you can not click them after the animation. 我正在尝试运行一个简单的动画,然后删除div,因为它位于某些按钮上,因此您不能在动画之后单击它们。

JS JS

$(".intro").eq(0).delay(800).animate({"opacity":"0"},1000 );

I tried doing this to remove the element after the animation but it removes it before. 我尝试这样做是为了在动画之后删除该元素,但之前却将其删除。

$(".intro").eq(0).delay(800).animate({"opacity":"0"},1000 ).remove();

Remove in animate function's callback: 在动画函数的回调中删除:

$(".intro").eq(0).delay(800).animate({opacity: 0}, 1000, function() {
  $(this).remove()
});

Alternatively, add complete function in option object: 或者,在选项对象中添加完整功能:

$(".intro").eq(0).delay(800).animate({opacity: 0}, {duration: 1000, complete: function() {$(this).remove();}});

You can add more options to it, easing for example. 您可以向其中添加更多选项,例如,宽松。 Check the API doc 检查API文档

You can use complete callback to call once the animation is complete : 动画完成后,您可以使用complete回调进行调用:

 $(".intro").eq(0).delay(800).animate({"opacity":"0"},1000, function() {
      $(this).remove();
 });

Working Demo 工作演示

Use the complete callback 使用完整的回调

 $(".intro").eq(0).delay(800).animate({"opacity":"0"},1000, function() { $(this).remove(); } ); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="intro">Hello</div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM