Reputation:
I'm simply trying to delay an action before it starts but I seem to be having some trouble.
This is my code:
$(document).ready(function(){
$(".action1").bind("load", function () { $(this).fadeOut('slow'); });
$(".action2").bind("load", function () { $(this).fadeIn('slow'); });
});
And I basically want to delay the first action from taking place just for a few seconds (onLoad).
Upvotes: 1
Views: 1354
Reputation: 29160
try using the delay()
function
$(document).ready(function(){
$(".action1").bind("load", function () { $(this).delay(2000).fadeOut('slow'); });
$(".action2").bind("load", function () { $(this).fadeIn('slow'); });
});
Upvotes: 1
Reputation: 100321
Wrap your function calls in setTimeout
.
setTimeout( func, delay );
setTimeout(function() {
/* your code */
}, 1000);
Upvotes: 0
Reputation: 82903
Try this(added delay for the first element before fadeOut call):
$(document).ready(function(){
$(".action1").bind("load", function () { $(this).delay(2000).fadeOut('slow'); }); //Delay for 2 seconds
$(".action2").bind("load", function () { $(this).fadeIn('slow'); });
});
Reference: http://api.jquery.com/delay/
Upvotes: 3