I'm trying to create an effect where the page loads, and after 5 seconds, the success message on the screen fades out, or slides up.
How can I achieve this?
I'm trying to create an effect where the page loads, and after 5 seconds, the success message on the screen fades out, or slides up.
How can I achieve this?
I realize that this is an old question, but here's a plugin to address this issue that someone might find useful.
https://github.com/madbook/jquery.wait
lets you do this:
$('#myElement').addClass('load').wait(5000).addClass('done');
The reason why you should use .wait instead of .delay is because not all jquery functions are supported by .delay and that .delay only works with animation functions. For example delay does not support .addClass and .removeClass
Or you can use this function instead.
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
sleep(5000);
For a quick and easy delay using aynsc/await you can do:
await $(window).delay(5000).promise();