There are several ways to do this using jQuery
,some are :
You can use setTimeOut()
of jQuery
calling a function after a certain time or executing a code after a time (in milliseconds).
Example :
function explode(){
alert("Boom!");
}
setTimeout(explode, 2000);
Above in the code, explode()
will run in 2 seconds(2000 milliseconds).
For better understanding, I advise you to look here in the documentation on this function.
You can use too animate()
which also has a similar function to be able to execute a code snippet or function at a given time.
Example :
var x = document.getElementById('home_page');
$(x).animate({opacity:1.0},2000);
In the above example, animate()
will give opacity to home_page
in 2 seconds(2000 milliseconds).
For better understanding I advise you to take a look at the official documentation here.
Thanks for your help!
– miriam
how do I make the animation happen automatically after a few seconds and not after clicking the button? thanks
– miriam
You can declare the
setTimeout(function(){//codigo de transicao aqui}, 2000);
in this case, 2000 means 2 seconds, since the time is set in milliseconds.– Andrew Ribeiro