<!DOCTYPE html>
<html>
<head>
<title>setTimeout y SetInterval</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link type="text/javascript" rel="stylesheet" href="estilos.css">
<script src="javascript.js" type="text/javascript"></script>
</head>
<body>
<h1>Ejercicio Javascript con las funciones setTimeout y SetInterval </h1>
<div id="crecer"></div><!--En el div hay una imagen de fondo de determinadas dimensiones,
lo que va creciendo de tamaño es el div, no la foto, hasta que esta se ve entera-->
</body>
</html>
i=0; //iniciamos la variable i de forma global. Va a ser la que recorra el array.
function mostrar_foto(){
i++; //Incrementamos la i.
dimension=["100px","200px","300px","400px","500px", "600px"]; //Definimos el array con los valores que va a tomar el ancho y el alto.
document.getElementById('crecer').style.width=dimension[i]; //Accedemos al elemento para cambiar su tamaño, el ancho.
document.getElementById('crecer').style.height=dimension[i];//Accedemos al elemento para cambiar su tamaño, el alto.
}
var temporizador=setInterval(mostrar_foto,3000); //Con esta función llamamos a la funcion mostrar_foto en un intervalo de tiempo de 3 segundos y lo guardamos en la variable temporizador.
function mostrar_mensaje(){
clearInterval(temporizador);//Cuando este se ejecute se para la función setInterval
alert('Mi primera animación: Creada por Francisco Gil Merino');//Finalizamos el ejercicio con un alert
}
setTimeout(mostrar_mensaje,19000); //Con esta función llamamos a la función mostrar_mensaje a los 19 segundos de haberse cargado la página.
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.