Foros del Web » Programando para Internet » Javascript »

Problema en firefox con imagen de fondo adaptable

Estas en el tema de Problema en firefox con imagen de fondo adaptable en el foro de Javascript en Foros del Web. Buenas, Quiero usar una imagen de fondo en la página, que se adapte al tamaño de la ventana, he usado este script, que me funciona ...
  #1 (permalink)  
Antiguo 18/03/2011, 10:09
 
Fecha de Ingreso: enero-2011
Mensajes: 15
Antigüedad: 13 años, 3 meses
Puntos: 0
Pregunta Problema en firefox con imagen de fondo adaptable

Buenas,
Quiero usar una imagen de fondo en la página, que se adapte al tamaño de la ventana, he usado este script, que me funciona bien con el ie, pero me falla con otros navegadores como el firefox,

Código:
<script language=javascript> 
function ini()    { 
    var elFondo = document.getElementById("fondo").style 
    var myWidth = 0, myHeight = 0;
  
        if( typeof( window.innerWidth ) == 'number' ) {
            //Non-IE
            
            myWidth = window.innerWidth
            myHeight = window.innerHeight
            
  
        } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
          //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth
            myHeight = document.documentElement.clientHeight
 
        } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth
            myHeight = document.body.clientHeight
 
        }
//hasta aqui bien para FF

    elFondo.width = myWidth  
    elFondo.height= myHeight
}
</script>
Si saco por pantalla la variable elFondo.width me da 0pt, en cambio si saco myWidth me devuelve el valor correcto.

¿Alguien sabe como realizar esa asignación para que funcione en Firefox?

Saludos y gracias!
  #2 (permalink)  
Antiguo 18/03/2011, 10:32
Avatar de Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Problema en firefox con imagen de fondo adaptable

No le estás agregando la unidad de medida. Así funciona:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<
title>Documento sin título</title>

</
head>

<
body>
<
div id="fondo"></div>
<
script language=javascript
function 
ini()    { 
    var 
elFondo document.getElementById("fondo").style 
    
var myWidth 0myHeight 0;
  
        if( 
typeofwindow.innerWidth ) == 'number' ) {
            
//Non-IE
            
            
myWidth window.innerWidth
            myHeight 
window.innerHeight
            
  
        
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
          
//IE 6+ in 'standards compliant mode'
            
myWidth document.documentElement.clientWidth
            myHeight 
document.documentElement.clientHeight
 
        
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            
//IE 4 compatible
            
myWidth document.body.clientWidth
            myHeight 
document.body.clientHeight
 
        
}
//hasta aqui bien para FF

    
elFondo.width myWidth +'px'
    
elFondo.heightmyHeight+'px';
    
alertelFondo.width)
}
ini();
</script>
</body>
</html> 
  #3 (permalink)  
Antiguo 18/03/2011, 11:17
 
Fecha de Ingreso: enero-2011
Mensajes: 15
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: Problema en firefox con imagen de fondo adaptable

Cita:
Iniciado por Panino5001 Ver Mensaje
No le estás agregando la unidad de medida.
...
Muchas gracias!!

Ya va perfecto.

Etiquetas: firefox, fondo
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 02:38.