Skip to content Skip to sidebar Skip to footer

How To Slow Down The Animation?

I have animation rectangle jsFiddle Demo How to slow down the animation and make it more stable? I try to use loop delay but there is conflict between the delay loop and requestAn

Solution 1:

One option to slow down your particular function would be to make it run only every X frames,

Editing your RandomPosition() to something like this makes it run once every 10 frames:

var counter=0;
functionRandomPosition() {
    if(++counter % 10){
        window.requestAnimationFrame(RandomPosition);
        returnfalse;
    }

http://jsfiddle.net/jaibuu/kHvaX/1/

Solution 2:

use this:

setInterval(code, milliseconds);

It returns a number that you need to save so you can stop the code. So we can write:

var interval = setInterval(function() {
     clock();
     x++;
     if (x > 90) clearInterval(interval);
 }, 30);

This creates a function that occurs every 30 milliseconds.

Every 30 milliseconds, clock() is called, x is incremented, and if x is more than 90 we call clearInterval and pass in the number that our call to setInterval returned. This makes sure that the code open happens 90 times total.

Post a Comment for "How To Slow Down The Animation?"