PDA

View Full Version : Some Javascript help...


xibitech
12-22-2006, 10:17 AM
Hi gurus,

I have a javascript program which calls two times a drawing function.
In order to determine where to start drawing i use the following functions that determine the initial X and Y coordinates of the two DIVs on which i draw:

function findPosX(obj) { var curleft = 0; if(obj.offsetParent) while(1) { curleft += obj.offsetLeft; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.x) curleft += obj.x; return curleft; }
function findPosY(obj) { var curtop = 0; if(obj.offsetParent) while(1) { curtop += obj.offsetTop; if(!obj.offsetParent) break; obj = obj.offsetParent; } else if(obj.y) curtop += obj.y; return curtop; }

The Symptom i get is that for some strange reason,it seems the Javscript executes "too fast" so the second time the function is called the X and Y coordinates are wrongly calculated (the HTML definition and the function call for both DIVs is identhical).
I was wondering whether we can pause the function execution for a number of miliseconds and then make it continue so the coordinates will be calculated right.

Any hints?
Thanks.