It's cool man, i had figured it out.
Just use setTimeout function like this
Code:
// ms = 1000 / fps
// 1000 / 40(fps) = 25(ms)
var timeMs = 25;
setTimeout("moveButton",timeMs);
function moveButton()
{
displayAnimation();
setTimeout("moveButton",timeMs);
}
And i even managed to play / stop animation on click.
Code:
var timeMs = 25;
start();
function moveButton()
{
if ( ! looping ) return;
displayAnimation();
setTimeout("moveButton",timeMs);
}
function start()
{
if ( looping ) return;
setTimeout("moveButton",timeMs);
looping = true;
}
function stop()
{
if ( ! looping ) return;
looping = false;
}