Hi folks

Please forgive me if this is discussed elsewhere, but I haven't found
anything that helps. Also, please forgive the clumsy code - I'm just
starting to really figure out how to use js and jquery properly. I
plan to chain these together, but I want to get it working first!

I'm trying to center an image in a div, but it's only working some of
the time. My code:

function swapPhotos(newImg) {
        if (activePhoto == 0) {
                activePhoto = 1;
                $("#photo2").html(newImg);
                var oV = 197 - $("#photo2 img").height() / 2 + "px";
                $("#photo2 img").css({ 'top': oV }).fadeIn("slow");
                $("#photo1 img").fadeOut("slow");
        } else {
                activePhoto = 0;
                $("#photo1").html(newImg);
                var oV = 197 - $("#photo1 img").height() / 2 + "px";
                $("#photo1 img").css({ 'top': oV }).fadeIn("slow");
                $("#photo2 img").fadeOut("slow");
        }
        $(".caption").text($(newImg).attr("alt"));
}

newImg is a piece of html with an img tag in it, returned from $get.
The swap happens every few seconds, but jQuery sometimes returns the
correct image height, sometimes not.

Here it is in action:
http://dev.vigoratecommerce.com/iSynApp/userGroupDisplay.action?sid=71&urgId=10000

Any help would be greatly appreciated.

cheers
dafydd

Reply via email to