Okay, it might be because I’m feeling a little sick, or it might be that this genuinely makes no sense:
I’m trying to make a simple function that moves (animates) a div downwards at a constant speed over a distance.
Both the distance and the div (via id) should be passed to the function so that it can be used with any div on the site and so it’s easily usable in the future.
The code is as follows:
[code=php]
function drop_div(wDiv, pixels)
{
//alert(“hello world”);
drop_cont(wDiv, pixels, 0);
}
function drop_cont(wDiv, pixels, cur_pixels)
{
alert(wDiv);
if(pixels > cur_pixels)
{
cur_pixels += 1;
document.getElementById(wDiv).style.top += 1;
setTimeout ( “drop_cont(” + wDiv + “, ” + pixels + “, ” + cur_pixels + “)”, 10 );
}
}
There are two functions just to be neat (no need to send the function 0 the first time for the third parameter).
The issue happens the first time drop_cont calls itself. Errors suggested it had something to do with wDiv being undefined or pointing at nothing the second time through so i threw the alert in to trace it. I expected it to give me a null, instead it returned the placeholder for an actual object ([object HTMLDivElement]).
So what I’m assuming is that somehow my String is getting automatically associated with the Div object it is the ID for. I have no idea why or how exactly to fix it. I’ve tried using temporary variables (mirroring the sent ones) so I can typecast and whatnot but it’s all for naught.
Any help would be GREATLY appreciated, thanks in advance.
-S