I am using the jQuery animate method in which I want to call a function when the animation is complete. Since the function is called several times in a loop, I need to access some variable but do not know how to do this (something to do with closures I guess).
I have :
while (i<numberofTimeIntervals)
{   
     // some calculations here
     xPos = initialPosX + x + "px";
     yPos = initialPosY - y + "px";
     $("#object").animate({left: xPos},10).animate({top: yPos},10, function(){ console.log(xPos) });  <-- what I want here is the access to xPos and yPos
     i = i + 1;
}
So I need to have access to xPos and yPos at the time it is calculated as the callback is called at a later time.
JD.
 
     
     
     
     
    