Foros ZackYFileS

Foros ZackYFileS (http://foros.zackyfiles.com/index.php)
-   PROGRAMACIÓN Lenguajes: Visual Basic, C++, etc (http://foros.zackyfiles.com/forumdisplay.php?f=370)
-   -   Precarga de imágenes en JavaScript (http://foros.zackyfiles.com/showthread.php?t=359007)

Pillus 09/10/2005 10:38

Precarga de imágenes en JavaScript
 
Este codigo modificado es un "preload de imagenes en JavaScript" que puede usarse como intercambiador de imagenes.

Ejemplo:

- Si tienes un boton (una imagen) y quieres que al pasar el cursor por encima, la imagen cambie:

Tendriamos que hacer una imagen llamada "02.gif" y con un color determinado
http://foros.marianistas.org/attachm...tid=2941&stc=1
Elaborar otra imagen igual pero con distinto color, y la llamamos "02_x.gif"
http://foros.marianistas.org/attachm...tid=2942&stc=1

Ahora nos vamos al documento sobre el que estemos trabajando e introducimos entre la etiqueta HEAD:

<head>
Código:


<SCRIPT TYPE="text/javascript">
miArray = new Array ("imagenes/02_x.gif");
patron = new RegExp("imagenes/");

for (cont=0;cont<miArray.length;cont++) {
eval ("imagen" + cont + " = new Image();");
eval ("imagen" + cont + ".src = " + "\"" + miArray[cont] + "\";");

}

cont=0;
function pruebaCarga() {

if (eval("imagen"+cont).complete == true) {
window.defaultStatus= "Imagen"+cont+ "/" + miArray.length + " CARGADA";
cont++;
}

if (cont<miArray.length) setTimeout('pruebaCarga()',500);
}
</SCRIPT>

</head>


y en la primera parte de la etiqueta BODY tendras que introducir:
Código:

<body onLoad="pruebaCarga();return true;">
y....LISTO !!!!

En la linea:
"miArray = new Array ("imagenes/02_x.gif");" tendrás que introducir la ruta de tu imagen (LA QUE ESTARA ESCONDIDA)


La franja horaria es GMT +2. Ahora son las 00:12.

Powered por vBulletin™ Version 3.8.10
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.
Traducido por vBsoporte - vBulletin en español
ZackYFileS - Foros de Debate