Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fade out div after x seconds with jquery

Tags:

I do a fade in div that is not displayed when I load the page:

    $('#overlay').fadeIn('fast');     $('#box').fadeIn('slow'); 

I would do this instructions after x seconds, doing a fadeOut of the div:

$('#overlay').fadeOut('fast'); $('#box').hide(); 

How can I do it? Actually fadeOut is done on button click.

The script is here: http://clouderize.it/cookie-localstorage/a.php The div that appear when I click on another image will disappear after x seconds. Thanks a lot.

like image 513
michele Avatar asked Nov 16 '12 22:11

michele


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);

What is fadeOut in jQuery?

jQuery Effect fadeOut() Method The fadeOut() method gradually changes the opacity, for selected elements, from visible to hidden (fading effect). Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: This method is often used together with the fadeIn() method.

What is the difference between fadeOut and hide in jQuery?

fadeOut() the place will be removed at once. . show(duration) and . hide(duration) animate the size of element (also the opacity) to 100% and 0% and the place of elements is also animated in that duration.

Which function need to use for toggling fade?

The fadeToggle() method toggles between the fadeIn() and fadeOut() methods. If the elements are faded out, fadeToggle() will fade them in. If the elements are faded in, fadeToggle() will fade them out.


1 Answers

The .delay method is purpose built for what you are describing:

$('#overlay').fadeIn('fast').delay(1000).fadeOut('fast'); $('#box').fadeIn('slow').delay(1000).hide(0); 

http://jsfiddle.net/SUBnz/1/

like image 105
Asad Saeeduddin Avatar answered Sep 27 '22 17:09

Asad Saeeduddin