![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
01/09/2008, 07:56
|
| | Fecha de Ingreso: agosto-2008
Mensajes: 32
Antigüedad: 16 años, 5 meses Puntos: 1 | |
Respuesta: Mostrar imagenes al azar Así a bote pronto: Código Javascript
var fotos = new Array();
// Introducimos las fotos en el array.
fotos[0] = "url de la foto 0";
fotos[1] = "url de la foto 1";
fotos[2] = "url de la foto 2"; // etc.
// Genera un número aleatorio dentro de un intervalo.
function aleatorio (inferior, superior)
{
var numPosibilidades = superior - inferior;
var aleat = Math.random() * numPosibilidades;
aleat = Math.round(aleat);
return parseInt(inferior) + aleat;
}
// Carga una foto aleatoria.
function cargarFotoAleatoria ()
{
document.getElementById("imagen_aleatoria").src = fotos[aleatorio(0, fotos.length-1)];
} Código HTML
<body onload="cargarFotoAleatoria()">
<img id="imagen_aleatoria" src=""/>
</body> |