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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:22:58+00:00 2026-05-29T21:22:58+00:00

I started writing some JS code to cause a variables value to increase over

  • 0

I started writing some JS code to cause a variables value to increase over time, up to a target value, with some form of ‘ease-in’.

I realised that jquery already does this in it’s .animate() method. Of course, the method is for manipulating CSS properties, not general variables.

My question is, is there anything that can be done to hack it so that the method affects a variable, rather than a CSS property?

  • 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-05-29T21:23:00+00:00Added an answer on May 29, 2026 at 9:23 pm

    Yes, you can animate variables. Demo here

    $({ n: 0 }).animate({ n: 10}, {
        duration: 1000,
        step: function(now, fx) {
            $("div").append(now + "<br />");
        }
    });
    

    In this example, I am animating n from 0 to 10 in 1 second. The step function is called during animation and from there you can retrieve the current value in now.

    Personally, I used this technique to animate several css properties simultaneously in a non linear fashion.

    Animate runs by modifying the value of properties declared in JS objects. Although animate is designed to change CSS scalar values, it can also safely be used for any generic property, as long value is a scalar one.
    In fact, you can think of CSS as a set of JS objects, where properties are for example, top, margin etc.

    Note that the following scripts do the same. They change CSS left from 0 to 10

    $("#test").css('left', 0).animate({ left: 10 }, 1000);
    

    is the same as

    $({ left: 0 }).animate({ left: 10 }, {duration: 1000, step: function(now, fx) {
      $("#test").css('left', now);
    }});
    

    or, without using the now parameter

    var obj = { left: 0 };
    $(obj).animate({ left: 10 }, {duration: 1000, step: function() {
          $("#test").css('left', obj.left);
    }});
    

    To see them in action click here

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

Sidebar

Related Questions

I'm writing some C++ code that will have to send data over TCP/IP. I
I'm writing some example code where an embedded Jetty server is started. The server
In writing some code today, I have happened upon a circumstance that has caused
What are some resources for getting started writing a Firefox Addon? Is there an
In my free time I started writing a small multiplayer game with a database
I have just installed C# 2008 Express Edition 2008 and started writing code. My
How do you get started generating native code for a target platform? I've got
I'm writing an AJAX function that returns some information to display in a <div>
Right now, I am trying to learn Scala . I've started small, writing some
I am currently re-writing an existing tool in PHP that another person started for

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.