Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/03/2011, 19:59
Avatar de junihh
junihh
 
Fecha de Ingreso: febrero-2004
Ubicación: República Dominicana
Mensajes: 997
Antigüedad: 22 años, 8 meses
Puntos: 7
img.onload aparenta no funcionar

Hola señores

Estoy haciendo una funcion tipo Lightbox, que muestre una imagen y descripcion sobre un layer oscuro. Lo hace bien, pero una variable que calcula el ancho de la imagen parece no estar calculando bien el ancho de la misma, no obstante use el evento ".onload".

Aca la funcion:

Código PHP:
showFotos.prototype.setMsg = function (ft,ti)
{
    var 
ths = this;
    
//
    
ths.glb.box = document.createElement ('div');
    
ths.glb.box.className = 'shBox';
    
document.body.appendChild (ths.glb.box);
    
ths.glb.box.style.display = 'none';
    
//
    
var fdo = document.createElement ('div');
    
fdo.className = 'shBox_fdo';
    
ths.glb.box.appendChild (fdo);
    
//
    
var cnt = document.createElement ('div');
    
cnt.className = 'shBox_cnt';
    
ths.glb.box.appendChild (cnt);
    
//
    
var img = new Image ();
    
img.src = ft;
    
img.onload = function ()
    {
        var 
fot = document.createElement ('img');
        
fot.src = ft;
        
cnt.appendChild (fot);
        
//
        
var tit = document.createElement ('p');
        
tit.innerHTML = ti;
        
cnt.appendChild (tit);
        
//
        
var fotW = fot.offsetWidth; // variable que calcula el ancho
        
cnt.style.width = fotW + 'px';
        
cnt.style.left = ((ths.winWH('w') - fotW) / 2) + 'px';
        
//
        
ths.glb.box.onmouseover = function () { this.style.cursor = 'pointer'; };
        
ths.glb.box.onclick = function () { document.body.removeChild (this); };
        
//
        
ths.glb.box.style.display = 'block';
    };
}; 
Como se ve, la variable "ftW" es la que guarda el ancho del calculo, asi que no estoy seguro si estare aplicando mal el ".onload". Si quieren, pueden ver aca la muestra.

¿Tienen alguna sugerencia o idea de como solucionar este impase? Gracias por cualquier ayuda que puedan prestarme.
__________________
JuniHH
- Mi blog
- Mi portafolio