Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery fade-out DIV display after certain set time

Tags:

jquery

I have the following code and would like to hide a DIV (.video-field-new) after a specified amount of time after the page loads, for example 5 seconds. Is that possible?

<div id="BodyField">
    <div class="video-field-new"></div>
</div>

And bonus if I could have it fade-out instead of just disappearing as the user will see this occurring.

like image 498
Dan Avatar asked Feb 27 '13 17:02

Dan


People also ask

How do you fadeOut an element in jQuery?

The jQuery fadeOut() method is used to fade out a visible element. Syntax: $(selector).fadeOut(speed,callback); The optional speed parameter specifies the duration of the effect.

What is FadeIn and fadeOut in jQuery?

The fadeIn method displays the element by fading it to opaque. The fadeOut method hides the element by fading it to transparent. Note – jQuery does the fading by changing the opacity of the element.

What is the difference between fadeOut and hide in jQuery?

Main difference between FadeIn, FadeOut vs hide, Show is When you use FadeIn and fadeout Its remove line Slowly Like Opacity will 100 to 0 in a few mili-second but On other hand hide, Show will remove the line immediately Without wasting any mili-second.

How does jQuery fadeOut work?

fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the display style property is set to none , so the element no longer affects the layout of the page. Durations are given in milliseconds; higher values indicate slower animations, not faster ones.


3 Answers

You can do it in this way

$("#BodyField").delay(5000).fadeOut();
like image 199
Starx Avatar answered Oct 21 '22 06:10

Starx


$(window).load(function(){
  setTimeout(function(){ $('.video-field-new').fadeOut() }, 5000);
});
like image 45
Denys Séguret Avatar answered Oct 21 '22 07:10

Denys Séguret


Try

$('#div').fadeIn('fast').delay(1000).fadeOut('fast');
$('#div-inner').fadeIn('slow').delay(1000).hide(0);

Thanks

like image 23
subindas pm Avatar answered Oct 21 '22 08:10

subindas pm