I'm trying to do a little javascript trick to fade out a div, replace its content, and fade it back in. The .html event is replacing the content before the fadeOut is complete...
$("#products").fadeOut(500) .delay(600) .html($("#productPage" + pageNum).html()) .fadeIn(500);
It appears that the .html()
is not being delayed by the .delay()
method.
jQuery delay() Method The delay() method sets a timer to delay the execution of the next item in the queue.
The delay() is an inbuilt method in jQuery which is used to set a timer to delay the execution of the next item in the queue. para1: It specifies the speed of the delay. para2: It is optional and specifies the name of the queue.
Conclusion. setTimeout() is a method that will execute a piece of code after the timer has finished running. let timeoutID = setTimeout(function, delay in milliseconds, argument1, argument2,...); The delay is set in milliseconds and 1,000 milliseconds equals 1 second.
delay
will work for your case when used with the queue
like this:
$("#products").fadeOut(500) .delay(600) .queue(function(n) { $(this).html("hahahhaha"); n(); }).fadeIn(500);
Try it here: http://jsfiddle.net/n7j8Y/
Maybe the "queue" way it's ok, But this javascript solution works better for me:
setTimeout (function(){ $("#products").html('Product Added!'); },1000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With