Foros del Web » Programando para Internet » Javascript »

JavaScript Vs Firefox

Estas en el tema de JavaScript Vs Firefox en el foro de Javascript en Foros del Web. Buenos dias a todos. En primer lugar, gracias por el tiempo. Vamos a ello. Estoy creando una web que tiene una imagen de fondo que ...
  #1 (permalink)  
Antiguo 18/06/2008, 04:02
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 0
JavaScript Vs Firefox

Buenos dias a todos.
En primer lugar, gracias por el tiempo.

Vamos a ello.
Estoy creando una web que tiene una imagen de fondo que cambia cada x tiempo con un barrido. Esta función de JS me funciona bien en Opera, Safari, IE...pero en Firefox no hay manera.
Con la consola detecté un error de getelementbytagname que ya está solucionado. Ahora el FF no me da error, pero sigue sin verse nada de nada.

Les dejo los códigos aquí abajo por si pueden echarme un cable.

El JS.

Código:
// IXF1.0 :: Image cross-fade 
// *****************************************************
// DOM scripting by brothercake -- http://www.brothercake.com/
//******************************************************
//global object
var ixw = { 'clock' : null, 'count' : 1 }
var tiempo;
var imagenes = new Array("imagenes/imagen1.jpg","imagenes/imagen2.jpg","imagenes/imagen3.jpg", "imagenes/imagen4.jpg","imagenes/imagen5.jpg","imagenes/imagen6.jpg", "imagenes/imagen7.jpg","imagenes/imagen8.jpg","imagenes/imagen9.jpg","imagenes/imagen10.jpg"); 

/*******************************************************



/*****************************************************************************
 List the images that need to be cached
*****************************************************************************/

ixw.imgs = [
	'imagenes/imagen1.jpg',
	'imagenes/imagen2.jpg',
	'imagenes/imagen3.jpg',
	'imagenes/imagen4.jpg',
	'imagenes/imagen5.jpg',
	'imagenes/imagen6.jpg',
	'imagenes/imagen7.jpg',
	'imagenes/imagen8.jpg',
	'imagenes/imagen9.jpg',
	'imagenes/imagen10.jpg',
	];

/*****************************************************************************
*****************************************************************************/



//cache the images
ixw.imgsLen = ixw.imgs.length;
ixw.cache = [];
for(var i=0; i<ixw.imgsLen; i++)
{
	ixw.cache[i] = new Image;
	ixw.cache[i].src = ixw.imgs[i];
}

function aleatorio(inferior,superior){ 
    numPosibilidades = superior - inferior 
    aleat = Math.random() * numPosibilidades 
    aleat = Math.floor(aleat) 
    return parseInt(inferior) + aleat 
} 

//crosswipe setup function
function crosswipe()
{
	
	//if the timer is not already going
	if(ixw.clock == null)
	{
		//copy the image object 
		ixw.obj = arguments[0];
		
		//get its dimensions
		ixw.size = { 'w' : ixw.obj.width, 'h' : ixw.obj.height };
		
		//copy the image src argument 
		var n=aleatorio(0,9);
		//alert (n);

		ixw.src = imagenes[n];
		
		//change the image alt text if defined
		if(typeof arguments[3] != 'undefined' && arguments[3] != '')
		{
			ixw.obj.alt = arguments[3];
		}

		//if dynamic element creation is supported
		if(typeof document.createElementNS != 'undefined' || typeof document.createElement != 'undefined')
		{
			//create a new image object and append it to body
			//detecting support for namespaced element creation, in case we're in the XML DOM
			ixw.newimg = document.getElementsByTagName('span')[0].appendChild((typeof document.createElementNS != 'undefined') ? document.createElementNS('http://www.w3.org/1999/xhtml', 'img') : document.createElement('img'));

			//set positioning classname
			ixw.newimg.className = 'idupe';

			//set src to new image src
			ixw.newimg.src = ixw.src

			//move it to superimpose original image
			ixw.newimg.style.left = ixw.getRealPosition(ixw.obj, 'x') + 'px';
			ixw.newimg.style.top = ixw.getRealPosition(ixw.obj, 'y') + 'px';

			//set it to be completely hidden with clip
			ixw.newimg.style.clip = 'rect(0, 0, 0, 0)';

			//show the image 
			ixw.newimg.style.visibility = 'visible';

			//copy and convert fade duration argument 
			ixw.length = parseInt(arguments[1], 10) * 1000;

			//create fade resolution argument as 20 steps per transition
			ixw.resolution = parseInt(arguments[1], 10) * 20;

			//copy slide direction argument
			ixw.dir = arguments[2];

			//start the timer
			ixw.clock = setInterval('ixw.crosswipe()', ixw.length/ixw.resolution);
		}
		
		//otherwise if dynamic element creation is not supported
		else
		{
			//just do the image swap
			ixw.obj.src = ixw.src;
		}
		
	}
};


//crosswipe timer function
ixw.crosswipe = function()
{
	//decrease the counter on a linear scale
	ixw.count -= (1 / ixw.resolution);
	
	//if the counter has reached the bottom
	if(ixw.count < (1 / ixw.resolution))
	{
		//clear the timer
		clearInterval(ixw.clock);
		ixw.clock = null;
		
		//reset the counter
		ixw.count = 1;
		
		//set the original image to the src of the new image
		ixw.obj.src = ixw.src;
	}
	
	//animate the clip of the new image
	//using the width and height properties we saved earlier
	ixw.newimg.style.clip = 'rect('
		+ ( (/bt|bltr|brtl/.test(ixw.dir)) ? (ixw.size.h * ixw.count) : (/che|cc/.test(ixw.dir)) ? ((ixw.size.h * ixw.count) / 1) : (0) )
		+ 'px, '
		+ ( (/lr|tlbr|bltr/.test(ixw.dir)) ? (ixw.size.w - (ixw.size.w * ixw.count)) : (/cve|cc/.test(ixw.dir)) ? (ixw.size.w - ((ixw.size.w * ixw.count) / 1)) : (ixw.size.w) )
		+ 'px, '
		+ ( (/tb|tlbr|trbl/.test(ixw.dir)) ? (ixw.size.h - (ixw.size.h * ixw.count)) : (/che|cc/.test(ixw.dir)) ? (ixw.size.h - ((ixw.size.h * ixw.count) / 1)) : (ixw.size.h) )
		+ 'px, '
		+ ( (/lr|tlbr|bltr/.test(ixw.dir)) ? (0) : (/tb|bt|che/.test(ixw.dir)) ? (0) : (/cve|cc/.test(ixw.dir)) ? ((ixw.size.w * ixw.count) / 1) : (ixw.size.w * ixw.count) ) 
		+ 'px)';
			
	//keep new image in position with original image
	//in case text size changes mid transition or something
	ixw.newimg.style.left = ixw.getRealPosition(ixw.obj, 'x') + 'px';
	ixw.newimg.style.top = ixw.getRealPosition(ixw.obj, 'y') + 'px';
	
	//if the counter is at the top, which is just after the timer has finished
	if(ixw.count == 1)
	{
		//remove the duplicate image
		ixw.newimg.parentNode.removeChild(ixw.newimg);
	}
};



//get real position method
ixw.getRealPosition = function()
{
	this.pos = (arguments[1] == 'x') ? arguments[0].offsetLeft : arguments[0].offsetTop;
	this.tmp = arguments[0].offsetParent;
	while(this.tmp != null)
	{
		this.pos += (arguments[1] == 'x') ? this.tmp.offsetLeft : this.tmp.offsetTop;
		this.tmp = this.tmp.offsetParent;
	}
	
	return this.pos;
};
El HTML

Código HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<script type="text/javascript" src="crosswipe.js"></script>
    <link href="transforma.css" rel="stylesheet" type="text/css" />
	<title>Transforma.cat</title>
    <!--[if lt IE 7]>
	<script src="IE7.js" type="text/javascript"></script>
	<![endif]-->

</head>

<body>
	<div id="frontal">Carrer Carders 17, 1er 2a<br />08003 Barcelona<br />T +34 932 690 428<br />E <a href="mailto:[email protected]">[email protected]</a></div>
	<div id="contenido">P&aacute;gina en construcci&oacute;n <br /> Website under construction</div>
	<div id=fondo><span><img id="test" src="imagenes/imagen1.jpg" /></span>
    <script> setInterval("crosswipe(document.getElementById('test'),'2', 'tb')",10000); </script>
</div>

</body>
</html> 
Y, por útlimo, el CSS

Código HTML:
body{
font-family:Verdana, Arial, Helvetica, sans-serif;
background-color:#999999;
font-size:11px;
overflow:hidden;
margin:0px;
padding:0px;
line-height:13px;
}

/* default opacity for IE */
img {
	filter:alpha(opacity=100);
	}

/* duplicate image positioning */
img.idupe {
	position:absolute;
	z-index:30000;
	visibility:hidden;
	}

A:link, A:visited { text-decoration: none; color:#000000 }
A:hover { text-decoration: underline; color:#000000 }

#fondo{
position: absolute;
z-index:-1; 
top: 0; 
left: 0; 
width: 100%;
overflow:hidden; 
}

#frontal{
padding-top:8px;
padding-left:8px;
position:absolute;
height:224px;
width:352px;
left:16px;
top:16px;
background-image:url(imagenes/pantalla-trans.png);
/*Esta ñapa es para que el png funcione en IE, viva esa panda de ***** */   
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, src='imagenes/pantalla-trans.png', sizingMethod='fit');
z-index:0;
}

#contenido{
padding-top:8px;
padding-left:8px;
position:absolute;
height:224px;
width:352px;
left:392px;
top:16px;
z-index:0;
background-color:#FFFFFF;
}

.imagen{
position: absolute; 
top: 0; 
left: 0; 
width: 100%;
}

#portada{
position:absolute;
left:16px;
top:16px;
}
Gracias de nuevo.
  #2 (permalink)  
Antiguo 18/06/2008, 04:09
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Respuesta: JavaScript Vs Firefox

Hola Proyecto_Zoulou, bienvenido a los foros :

El primer error que he visto es que el array ixw.imgs termina con una coma sin nada detrás... deberías borrar esa coma (seguro de algún copy & paste)

Iremos viendo más cosas...

Saludos
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #3 (permalink)  
Antiguo 18/06/2008, 04:24
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: JavaScript Vs Firefox

Gracias por la rapidez caricatos.

Seguro no, segurísimo... Pasa por meterle al copy&paste a lo burro.
Bueno, eso ya esta fuera! Aunque como bien sabes, esto al FF ni le inmuta, sigue igual.
  #4 (permalink)  
Antiguo 18/06/2008, 07:24
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: JavaScript Vs Firefox

¿Has probado a ir debugueando con Firebug y ver a dónde llega?
  #5 (permalink)  
Antiguo 18/06/2008, 14:58
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: JavaScript Vs Firefox

Hola venkman, gracias por tu respuestas.
A lo que me referia con consola era el firebug, me pasa sin errores.

Gracias
  #6 (permalink)  
Antiguo 19/06/2008, 01:38
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: JavaScript Vs Firefox

Hola!
He colgado la página por si os es más cómodo ver, está en http://transforma.cat/nuevo (Disculpad, el foro no me deja las url por temas de spam)

Salu2
  #7 (permalink)  
Antiguo 19/06/2008, 07:01
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: JavaScript Vs Firefox

Pues con Firefox lo estoy viendo y funciona.

Pero con lo de debuguear, me refería no sólo a mirar la consola, sino a ir siguiéndolo paso a paso y viendo si alguna variable se queda a null o alguna cosa similar.
  #8 (permalink)  
Antiguo 19/06/2008, 08:31
Avatar de elcamaleon007  
Fecha de Ingreso: julio-2004
Ubicación: Asunción - Paraguay
Mensajes: 256
Antigüedad: 19 años, 9 meses
Puntos: 0
Respuesta: JavaScript Vs Firefox

estoy viendo con el FF 3.0 y funciona correctamente.. saludos!
__________________
La diferencia entre el 1ro y el 2do son milésimas..si hariamos un poco mas de lo que hacemos normalmente..bue, creo que ya entendiste...Exitos!
  #9 (permalink)  
Antiguo 19/06/2008, 20:15
 
Fecha de Ingreso: octubre-2003
Ubicación: Cerca de una wifi o 3G
Mensajes: 328
Antigüedad: 20 años, 6 meses
Puntos: 4
Respuesta: JavaScript Vs Firefox

Yo no lo veo

FF 2.0.14

Prueba con esto ya que esta medio desordenado el html y es mejor estar seguro de que todo ha sido cargado
Código HTML:
<body onload="setInterval("crosswipe(document.getElementById('test'),'2', 'tb')",10000);">
	<div id="frontal">Carrer Carders 17, 1er 2a<br />08003 Barcelona<br />T +34 932 690 428<br />E <a href="mailto:[email protected]">[email protected]</a></div>
	<div id="contenido">P&aacute;gina en construcci&oacute;n <br /> Website under construction</div>
	<div id=fondo><span><img id="test" src="imagenes/imagen1.jpg" /></span>
</div> 
Saludos
__________________
Ayuda!! firmar y compartir
No a la privatizacion de semillas http://www.thepetitionsite.com/1/no-...n-de-semillas/
Mas info: http://chilesintransgenicos.cl/
  #10 (permalink)  
Antiguo 20/06/2008, 02:46
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: JavaScript Vs Firefox

Hola a todos de nuevo!
Venkman, no lo había entendido al principio, he arrancado la web con el firebug, la consola, el inspector de DOM...
El Inspector me da un par de advertencias sobre el css con las propidades opacity para windows (Hasta aquí normal). Después, me suelta una rista de errores pero no sólo para mi web sino que también en google, etc. Se trata de problemas como:

Error: Warning: unrecognized command line flag -psn_0_147492

Archivo de origen: file:///Applications/Firefox.app/Contents/MacOS/components/nsBrowserContentHandler.js
Línea: 706


o

No chrome package registered for chrome://communicator/content/utilityOverlay.xul .


Aparte de eso no me dice nada nuevo, y el firebug me da null en algunas cosas pero no les veo relación porque también las da en otras webs.

Lo bueno es que la .Net me va cargando las imágenes, por lo que el script funciona, lo que no veo es por que no se visualizan...

Remsankar, yo uso la misma versión de FF, he probado lo que me has dicho pero no me funciona si le meto un onload, aun así, en el ordenador le he subido el script hasta dejarlo al ppio, justo por debajo del body...
  #11 (permalink)  
Antiguo 20/06/2008, 03:42
venkman
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: JavaScript Vs Firefox

Bueno, lo que yo he podido ver con el Firebug es:

1. las imagenes se cargan y se refrescan correctamente. El script funciona.
2. El problema es de visibilidad / orden de capas. Si a #fondo le quitas ese z-index: -1 que tiene, podrás ver que las imágenes se cargan y se refrescan.

Se me ocurre que lo que podrías hacer es, en lugar de ponerle ese z-index a #fondo, podrías ponerles un z-index más algo a los otros divs. No es una solución muy limpia que digamos pero es que ahora mismo no veo por qué el color de fondo del body está quedando por encima de #fondo.

Otra cosa que se me ocurre, si quieres investigarlo mejor es que olvides el Javascript, que sabemos que está bien, y depures el CSS de forma estática.
  #12 (permalink)  
Antiguo 20/06/2008, 05:16
 
Fecha de Ingreso: junio-2008
Mensajes: 12
Antigüedad: 15 años, 10 meses
Puntos: 0
Respuesta: JavaScript Vs Firefox

Ostias!!!!
Muchas gracias Venkman, era lo del z-index, lo tenía así para que los divs estuviesen por encima porque se me cargaban las nuevas imagenes encima, y no me fije en que menos uno se iba para atrás.

Muchas gracias de nuevo a todos!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:06.