Take the 2-minute tour ×

I have explained in a comment where and what I want the code below to do:


maxspeed = 1.00;
    if  (maxspeed > 0.07)
            //This is where I want the max speed to countdown at
            //a decrement of -0.01 until it reaches 0.07

//Code continues below, I will edit post if required

My max speed is already stored in a variable with the value of 0.07. Any help would be appreciated, thanks.

[EDIT] Sorry, I should have explained better. I am pretty new to JS/jQuery and I have no idea how to use a count. I want my function to count down until it reaches a certain value.

share|improve this question
add comment

3 Answers

You should use a TimeInterval and start decreasing maxspeed by 0.07

maxspeed -= 0.07;

If you use a loop the action will be instant.

share|improve this answer
add comment

try this

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script language="javascript">


var maxspeed = 1.00;
var decrement = 0.01;


  function counter(maxspeed,decrement)
    while(maxspeed > parseFloat(0.07))
        maxspeed = parseFloat(maxspeed) - parseFloat(decrement);


share|improve this answer
Thanks, will give this a go, will need to make some tweaks to get it to work with my script though. –  Luke Oct 12 '11 at 9:50
okk................ –  mithunsatheesh Oct 12 '11 at 10:13
Hmm, i've posted a jsfiddle here - jsfiddle.net/62mnS With the alert enabled I can see that it does count down, but I have 2 problems: 1. It has no affect on the speed of the animation 2. It gets stuck once 'maxspeed' it reaches 0.7 If you remove the code you've told me to add, you can see what it did originally. –  Luke Oct 12 '11 at 10:30
add comment

Your Answer


