JQuery - callback en attr(src,x)

 
Vista:

callback en attr(src,x)

Publicado por oscar.tt (3 intervenciones) el 22/04/2012 16:14:35
Hola a todos.
Tengo el siguiente problema:

el flujo de ejecucion no espera a que attr termine de cargar la imagen: lo hace durante la animacion. Si pongo un alert(1) despues de im.attr, todo va perfectamente.
Se puede usar callback con attr? (lo probé, sin resultados)
Alguna sugerencia?
Gracias de antemano.


1
2
3
4
5
6
7
8
9
10
......
        im.attr("src",$(this).attr("href"));
        im.css({
            position: 'absolute',
            left: imgxica.offset().left,
            top: imgxica.offset().top,
            width: event.target.width,
            height: event.target.height
        });
        im.animate({left:posfi.left,top:posfi.top,width:700,height:400},400);
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 302
Oro
Ha mantenido su posición en JQuery (en relación al último mes)
Gráfica de JQuery

callback en attr(src,x)

Publicado por xve (673 intervenciones) el 22/04/2012 17:23:01
Te puede servir el método load()
Algo así:
1
2
3
4
5
6
7
8
9
10
11
im.attr("src",$(this).attr("href"));
im.load(function(){
    im.css({
        position: 'absolute',
        left: imgxica.offset().left,
        top: imgxica.offset().top,
        width: event.target.width,
        height: event.target.height
    });
    im.animate({left:posfi.left,top:posfi.top,width:700,height:400},400);
});
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

callback en attr(src,x)

Publicado por oscar.tt (3 intervenciones) el 22/04/2012 19:36:43
1
2
3
4
5
6
7
8
9
10
11
im.attr("src",$(this).attr("href"));
        im.css({
            position: 'absolute',
            left: imgxica.offset().left,
            top: imgxica.offset().top,
            width: event.target.width,
            height: event.target.height
        });
        im.load(function(){
            im.animate({left:posfi.left,top:posfi.top,width:700,height:400},400);
        });


xve, gracias por tu pronta respuesta.

Ajusté tu código y así me sirve más o menos.Sin embargo, no espera a terminar de cargar el atributo src que ya empieza la animación.

Entiendo que la function que pones dentro de load, es el callback, pero cual és el primero,el de peticion???
Voy a documentarme más sobre Load para saber que estoy haciendo.
Muchísimas gracias!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar