Click to See Complete Forum and Search --> : To Gollum:
xataku_nakusute
07-31-2003, 03:14 AM
i noticed the script you posted for the dude who wanted the circling images of his kids....and i was wondering...
could you help me wiht my dhtml(javascript style)?
cuz....i know my javascript pretty well...but im completely clueless on how to use that knowledge to create mini animations and stuff
Gollum
07-31-2003, 03:26 AM
What did you want to know?
xataku_nakusute
07-31-2003, 03:32 AM
sorry, i accidentally sent the PM to you before checking my thread again.....uhh...well....basically.....
one of my biggest problems is the increment operator in "realtime"
i cant get it to work, in an "animated way", i can only make it return an incremented value a certain amount of times.....so if you had an example that you could give me and explain, itd help me out alot
thanx
Gollum
07-31-2003, 03:55 AM
Hmm, little bit vague, but hope this helps...
animation in javascript is usually done using setTimeout (you could use setInterval, but setTimeout is supported by more browser versions). The idea is, you design your algorithm as itterations that move your animation forwards one step and then schedule the next move in a short period of time (about 40ms results in about 25 itterations per second)
So, so long as you always call window.setTimeout("MyAnimate();",40); at the end of your animation function, it will continue forever (Watch out for exceptions though).
For example, in the circle animation:
function Animate()
{
var nKids = data.kids.length;
for ( var i = 0; i < nKids; i++ )
{
var kid = data.kids[i];
kid.angle += data.dAngle;
kid.oDiv.style.top = Math.round(-Math.cos(kid.angle) * data.radius + (data.mum.height - kid.height) / 2);
kid.oDiv.style.left = Math.round(Math.sin(kid.angle) * data.radius + (data.mum.width - kid.width) / 2);
}
window.setTimeout("Animate();",data.dTime);
}
The Animate() function performs one itteration of the circle by cycling through each 'kid', adding a preset angle to the current one and then calculating the position coordinates for the <div> tag for that kid.
does this help?
xataku_nakusute
07-31-2003, 04:01 AM
yeah, it did help....however....i guess im not as good at javascript as i thought i was....and sorry to bother you, but i guess i need some more "basic" explanation of the increment variable(how it interacts with variables), and most importantly, loops(im familiar with them and have learned about them, however, im also a perl programmer and sometimes get the syntax confused, though most of the syuntax is similar)
thank you again for the extra time
Gollum
07-31-2003, 04:09 AM
'Fraid I can't really play instructor here, it is a bit too time consuming, or the commute is a bit much ;)
I don't want to sound like I'm passing you off, but I would thoroughly recommend you get a book on JavaScript - for example I found "JavaScript The Definitive Guide" by David Flanagan to be very good, and I keep it at my desk always.
xataku_nakusute
07-31-2003, 04:18 AM
ok....i was planning on either purchasing or checking out that book....i was unsure if it covered setTimeout and stuff like that in which are vital to the animations
but, pleaz, if you could, PM some tips/hints/help when you have time to spare if you want, and if not, dont worry bout it
thanx again for the consideration of my thread :D