Try putting that part in fadeIn's second parameter, a callback
function that executes after the fadeIn is completed:
$("#list .item a").click(function() {
var imgPath = $(this).attr("href");
$("#left p img").hide().attr({ src: imgPath })
.fadeIn(600, function() {
var workImgHigh = $("#work #left p img").height
();
$("#work #left p").css({"height":workImgHigh
+"px","margin-top":"-"+workImgHigh/2+"px","top":"50%"});
});
return false;
});
On Oct 5, 7:29 am, "[email protected]"
<[email protected]> wrote:
> Hi.
>
> I have written a quick function to change the src attribute of an
> image. I also need to set some CSS properties on that image's parent
> to get it to stay centered in the containing div. Here is the code
> I've written.
>
> $("#list .item a").click(function() {
> var imgPath = $(this).attr("href");
> $("#left p img").hide().attr({ src: imgPath }).fadeIn(600);
> var workImgHigh = $("#work #left p img").height();
> $("#work #left p").css({"height":workImgHigh+"px","margin-
> top":"-"+workImgHigh/2+"px","top":"50%"});
> return false;
> });
>
> The problem is that variable workImgHigh is getting set on the height
> of the original image in that spot, _before_ the src changes.
>
> How can I modify this to have the variable grab the height of the
> incoming image?
>
> Thanks much,
> Marcus