简体   繁体   English

jQuery fadeOut方法不会淡出元素

[英]jQuery fadeOut method is not fading out element

I am facing a peculiar problem while I am using jQuery fadeOut method. 我在使用jQuery fadeOut方法时遇到一个特殊的问题。

When I use below code it is fading out. 当我使用下面的代码时它会逐渐消失。

$('#id').fadeOut("slow" );

But when I use below code it is not fading out, it is just disappear from screen. 但是当我使用下面的代码时它不会消失,它只是从屏幕上消失了。

$('#id').fadeOut("slow" ).remove();

Could anyone say what is the problem ?? 谁能说出问题是什么?

Is there any way to make fading out the second one?? 有什么方法可以使第二个褪色吗?

Thanks 谢谢

The problem is that fadeOut is an animation method, which means it will happen over time, but you are then immediately invoking remove. 问题是fadeOut是一种动画方法,这意味着它会随着时间的推移而发生,但是你会立即调用remove。 Instead you can use the callback signature of fadeOut: 相反,您可以使用fadeOut的回调签名:

$('#id').fadeOut('slow', function(){
  $(this).remove();
});

使用callBack function ,通常在执行parental任务后会触发一次CallBacks

$('#id').fadeOut("slow",function(){ $(this).remove() } );

You need to wait for the fadeOut() to complete before removing it from the dom using the complete callback. 您需要等待fadeOut()完成,然后使用完整的回调将其从dom中删除。

$('#id').fadeOut("slow", function(){
   $(this).remove()
} );

its because of the .remove() method that runs concurrently with the animation which makes #id not yet completely faded out when remove() is executed. 这是因为.remove()方法与动画同时运行,使得在执行remove()#id尚未完全淡出。

You need to put the remove() on the fade-out callback 你需要在淡出回调上放置remove()

$('#id').fadeOut( function() { //the fadeout is finished call the callback function
   $(this).remove();
 });

我很确定你不需要使用remove()函数,因为fadeOut在完成淡入fadeOut也会删除元素。

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

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