Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery delay before fadeOut

Tags:

I have written a jquery script that allows me to fade divs in and out, then repeat. The code works fine. However, when I try to add a delay (I want the div to stay up a few seconds before fading out), it does not work properly. I've tried adding the delay in several places inside the code and none seem to function properly. I am using Jquery version 1.9.1

Here is the script that I have written:

$(document).ready(function(){    ShowPostDiv(0); });  function ShowPostDiv(divIndex) {     $(".home_entry_txt").hide();      if(divIndex >= $(".rotate_hide").length)     {         divIndex = 0;     }     var divPostHtml = $(".rotate_hide:eq("+divIndex+")").html();     $(".home_entry_txt").html(divPostHtml);      $(".home_entry_txt").fadeIn(3000, function(){              $(".home_entry_txt").fadeOut("slow");         });     divIndex++;     setTimeout("ShowPostDiv("+divIndex+")", 4000); } 
like image 888
user2220474 Avatar asked Mar 28 '13 16:03

user2220474


2 Answers

You can just write

$(".home_entry_txt").fadeIn(3000).delay(1000).fadeOut("slow"); 
like image 87
enb081 Avatar answered Oct 08 '22 01:10

enb081


Have you tried .delay()? something like:

$(".home_entry_txt").fadeIn().delay(200).queue(function(next) { $(".home_entry_txt").fadeOut("slow"); }); 
like image 35
kelly johnson Avatar answered Oct 07 '22 23:10

kelly johnson