Treehouse: Grow your CSS skills. Land your dream job.

How to increase or decrease increment speed in javascript?

  • # February 3, 2013 at 5:31 pm


    Is there any way to change increment speed (speed of a++ or a–) in javascript?

    If yes how? and where to put the code?

    Thanks in advance!


    # February 3, 2013 at 9:00 pm

    i’d need to see your code to know how to help you with your specific issue, but in the meantime this stackoverflow may hold your answer:

    see also:

    # February 4, 2013 at 3:30 am

    no you cant do it with ++ and — but you can do

    var bar = 5;
    var foo = (bar + 3);

    and foo would be 8. Or for — you could use

    var bar = 5;
    var foo = (bar – 3);

    and foo would be 2.

    Hope this is what you wanted. My JavaScript might not be right because i haven’t done JavaScript in a while.

    # February 4, 2013 at 3:37 am

    Actually I want to increase this script’s speed of 0 to 100.

    What’s your idea?

    # February 4, 2013 at 8:10 am

    in that case you could only change the setInterval number to a smaller number than 100.

    # February 4, 2013 at 8:18 am

    If the number at the end

    }, 100);

    were to be 1000, then the indicator will increment every 1000ms or every 1 second.

    You can adjust the increment speed with that.

    100 = 0.1s

    500 = 0.5s

    2000 = 2s

    # February 4, 2013 at 12:45 pm

    Yes, that’s it.

    Thank you Paulie! it worked.

    Now, If I want to use multiple of this progress bars inside of one page what I should do?

    When I put multiple progress bars in one page one of them works but the others not.

    # February 4, 2013 at 1:29 pm

    >If I want to use multiple of this progress bars inside of one page what I should do?

    Don’t….I can’t think of anything more annoying.

    # February 4, 2013 at 2:43 pm

    What do you mean by saying this?

    I have questions about web and will ask here because here is exactly the right place.

    # February 4, 2013 at 2:51 pm

    @AlirezaM, just change them to a class instead of id..

    > What do you mean by saying this?

    What he means, is that nothing is more annoying than coming to a website, and seeing 5 of these going on at different locations of the website…

    # February 4, 2013 at 3:09 pm

    The reason of doing this is that I show my costumers different colors of these progresses.

    Now, I changed those ids to classes but the problem is I want to put them different percentages but all of them works exactly like first one.

    I mean I give them for example : 10% , 20%, 30% and 40% but all of them work till 10%.

    # February 4, 2013 at 4:29 pm

    Try a little something like this:

    Note: This is not the cleanest of JS. I wrote this in a hurry, as a proof of concept. Use at your own risk. ;)

    # February 4, 2013 at 4:49 pm

    But if you read previous comments I could change the speed by Paulie’s helps.

    Now I want to use multiple progresses in one page.

    # February 4, 2013 at 4:54 pm

    Yes, that’s the question I addressed with my latest CodePen . . . it’s an example of multiple instances on the page, setting the percentage with a data attribute.

    # February 4, 2013 at 5:19 pm

    Yes man.

    Now it’s working.

    You noticed it’s not clean js, can you change it to be as clean as possible?

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic.