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 9143501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:02:28+00:00 2026-06-17T10:02:28+00:00

I have a simple function which is increasing the width of a div but

  • 0

I have a simple function which is increasing the width of a div but its not doing it smoothly its kinda of “juddery”.

I’m using request animation frame to do this on Chrome.. and I decided not to round the numbers so I could get decimal width increments.. but I can’t get it to be smooth at all was wondering how I can improve on my method.

This is my function:

function test(data){


var start = parseInt(data.start);
var length = parseInt(data.length); //total length in minutes to complete
var dif = (new Date().getTime() / 1000) - start; //start holds seconds since epoch
var minutes = dif / 60; //convert seconds past into minutes past
var percentage = (minutes/length) * 100;

if(percentage > 100){ percentage = 100; }

    if( percentage != 100 ){
        document.getElementById('r').style.width = percentage+'%';
        document.getElementById('rt').innerHTML = Math.round(percentage)+'%';
    } else if (percentage == 100 ){
        document.getElementById('r').style.width = percentage+'%';
        document.getElementById('rt').innerHTML = 'COMPLETED';
    }
}

My function is called like this:

window.requestAnimFrame = (function(){
  return  window.requestAnimationFrame       || 
          window.webkitRequestAnimationFrame || 
          window.mozRequestAnimationFrame    || 
          window.oRequestAnimationFrame      || 
          window.msRequestAnimationFrame     || 
          function( callback,  element){
            window.setTimeout(callback, 200 / 100);
          };
})();

function Update(){
    requestAnimFrame( Update ); 
    test();
}

JSFIddle: http://jsfiddle.net/RmXr9/7/

Any suggestions on ways to improve the smoothness of div width incrementing ?

  • 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-17T10:02:29+00:00Added an answer on June 17, 2026 at 10:02 am

    One of the biggest causes of ‘juddery’ animations for me has always been frame rate. If your frame rate is too slow, obviously the animation ‘judders’. But if it is too fast for the browser to handle, the browser gets confused, and you get a different kind of ‘juddery’.

    I’d recommend a frame rate of between 13 and 30 milliseconds. JQuery is supposed to use 13ms, but I’ve found that that is sometimes still too fast. I generally start with 16ms, and experiment from there.

    The key is to ensure that you time it so that one frame starts as or after the previous frame is finished. This will depend on the code you process. I notice that you call the next frame before you begin processing the current frame, so it may be possible that you’re still getting backed up. Perhaps try:

    function Update(){
        test();
        requestAnimFrame( Update ); 
    }
    

    Your fallback function has a frame rate of 200 / 100, which is 2ms. It is extremely unlikely that your browser can complete the animation in 2ms, so it is likelyto get backed up. requestAnimationFrame uses a maximum frame rate of 16ms.

    UPDATE:

    The problem you’re having, according to your jsfiddle, is that, while you’re calculating your percentage often, the changes to the percentage are very small, and they don’t translate into a change in the width of the div. This http://jsfiddle.net/RmXr9/13/ should demontrate the changes in the percentage, and show the corrsponding changes in actual width. So, although you do a calculation often (maybe 60 times a second), the actual visual change only happens once every 16 frames or so. So, your actual frame rate is only about 4 frames per second, which makes a ‘juddery’ animation. Your only options, I’m afraid, are to make the animation run faster (perhaps by decreasing your length variable), or to make the div much longer (or both).

    As an aside, I notice you don’t have a way to stop the animation at the end, and I’ve added that into the jsfiddle as well.

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

Sidebar

Related Questions

Using xlwDotNet, I have created a simple function which returns one number. Sometimes, something
I have a simple function in which a user will click on a div,
I have a simple function which takes an array of characters as an argument,
I have a simple C function which I declare as: int strLen(const char* str_)
I have a simple function, which I shall call myFunction . It takes two
I have written a simple jQuery.ajax function which loads a user control from the
I have a simple asp page with a script including a function myFunction which
I have a relatively simple class which deletes a post: function delete_post($postid, $reason){ //Stuff
I have a simple function that works in chrome, but in Internet explorer (9)
I have the simple function below which swap two characters of an array of

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.