CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   Race condition problem with jquery (http://www.codingforums.com/showthread.php?t=239470)

cmor 09-29-2011 04:15 PM

Race condition problem with jquery
 
I'm having trouble consistently getting the width of an element that is updated.

Here's a code snippet. I need to get the width of $newimg. You can see an attempt in line 5, var $imgwidth = $newimg.width() I've tried referring to it in a number of ways but the problem exists. If the image has already been loaded once it usually missess. I've tried a few when...then commands but got nowhere.

Code:

$('<img class="fp_preview" />').load(function(){
        var $newimg                = $(this);
        var $currImage        = $('#fp_gallery').children('img:first');
        $newimg.insertBefore($currImage);
        var $imgwidth        = $newimg.width();

        $loader.hide();
        //expand clone
        $theClone.animate({
                'opacity'                : 0,
                'top'                        : windowH/2 + 'px',
                'left'                        : windowW/2 + 'px',
                'margin-top'        : '-200px',
                'margin-left'        : -final_w/2 + 'px',
                'width'                        : final_w + 'px',
                'height'                : '400px'
        },1000,function(){$(this).remove();});
        //now we have two large images on the page
        //fadeOut the old one so that the new one gets shown


        $currImage.fadeOut(2000,function(){
                $(this).remove();
        });
       

        //show the navigation arrows
        showNav();
}).attr('src',$elem.attr('alt'))



All times are GMT +1. The time now is 06:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.