Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:53:55+00:00 2026-06-17T19:53:55+00:00

So, I am doing an animation (Not on a website/webpage!), that uses Javascript .

  • 0

So, I am doing an animation (Not on a website/webpage!), that uses Javascript. For the animation, I use requestAnimationFrame instead of setInterval, as setInterval did not work well enough for what I need.

However, although requestAnimationFrame works well on decently powered devices, slow devices can’t keep up with the standard 60 FPS, thereby slowing down the entire animation time.

Is there a way I can make the animation work under a time frame, and have the FPS vary depending on how well it keeps up? Other ideas are welcome as well.

(Note, I would really prefer not to post code, just take my word about this. I just want ideas)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:53:56+00:00Added an answer on June 17, 2026 at 7:53 pm

    Have a look at this demo: http://jsfiddle.net/q7ckebmh/

    function Animate(id, useTime){
        var can = document.getElementById(id),
            ctx = can.getContext('2d'),
            wid = can.width,
            hei = can.height,
            lst = Date.now(),
            rps = 2*Math.PI,
            step = rps/60,                       // Expecting 60fps
            ang = 0;
    
        (function draw(){
            var dif = Date.now() - lst;          // Milliseconds since last we drew. 
            lst = Date.now();                    
            if (useTime) step = rps * dif/1000;  // Allows for variable fps
    
            ang += step;                         // Increment our placeholder. In the 
                                                 // case where step is constant, this
                                                 // ends up looking "slow" when we 
                                                 // have less than 60fps. 
    
            ctx.clearRect(0,0,wid,hei);
            ctx.beginPath();
            ctx.arc(wid/2 + Math.cos(ang)*50,hei/2 + Math.sin(ang)*50, 
                10,0,2*Math.PI);
            ctx.fill();
    
            requestAnimationFrame(draw);
        })();
    }
    
    Animate('can1', false);
    Animate('can2', true);
    

    You’ll notice that if you resize the frame, the first animation will slow down since it is skipping animation frames.

    The second animation doesn’t appear to slow down because it bases the circle’s position on the time it has been since it was last called. It does look a little choppy, but the position is correct, always.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The marquee animation does not work, this is what I did. <LinearLayout android:layout_height=wrap_content android:layout_width=wrap_content
I'm doing some animation script in RPG Maker XP (made with ruby) that allow
(Note: I have seen this question and it uses a cursor not an animation.)
I'm doing this to learn how to work with Core Animation animatable properties on
I'm doing an animation using javascript: function animate(){ window.setTimeout(function(){ //Do a new frame and
I'm Doing a Javascript and jQUery animation and it is working quite fine in
While I am not doing some animation or drawing a very complicated graphics. I
I'm doing two animations on the same UIImageView, using blocks. Animations are not quite
Doing some jquery animation. I have certain divs set up with an attribute of
I'm doing jquery small animation of fade in to form validation This is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.