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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:02:48+00:00 2026-05-29T08:02:48+00:00

I am new to jquery, with some basic understanding. I am trying to use

  • 0

I am new to jquery, with some basic understanding.

I am trying to use the jOdometer.js https://github.com/jesucarr/jodometer . I can get the odometer well and good, and the default setInterval method makes the odometer tick.

There is a section of the code

function advanceCounter() {
            setNumbers(counter);
            counter = counter + settings.increment; // increment the number 
            // if we reach the end clear the interval and use the ending number
            if(settings.counterEnd != false && counter >= settings.counterEnd){
                clearInterval(counterInterval);
                setNumbers(settings.counterEnd);
            }
        }
        // to move the colums from one number position to another
        function setNumbers(counter){
            digits = String(counter).split('.'); // check decimals
            // if we where using decimals
            if (decimalsArray.length > 0){
                // for each decimal digit, update the old digit position to the new
                for (i=0;i<decimalsArray.length;i++){
                    oldDigit = decimalsArray[i];
                    // the new numer could have not decimal part, but we need it anyway
                    if (digits[1]){
                        decimalsArray[i] = digits[1].charAt(i);
                    }
                    if (decimalsArray[i] == ''){
                        decimalsArray[i] = '0';
                    }
                    updatePosition($('.jodometer_decimal_'+i, scope), parseInt(decimalsArray[i]), parseInt(oldDigit));
                }
            }

            integers = digits[0];
            j=integers.length-1;
            // for each integer digit, update the old digit position to the new
            for (i=0;i<integersArray.length;i++){
                oldDigit = integersArray[i];
                integersArray[i] = integers.charAt(j);
                if (integersArray[i] == ''){
                    integersArray[i] = '0';
                }
                //alert($(this));
                updatePosition($('.jodometer_integer_'+i, scope), parseInt(integersArray[i]), parseInt(oldDigit));
                j--;
            }
        }
        // changes the column position from one number to another
        function updatePosition(col, newDigit, oldDigit){
            if(newDigit != oldDigit){
                col.stop();
                // if the number is 0 use the bottom 0 in the image, and change intantly to the top 0
                if (newDigit == 0){
                    col.animate({top: (10*settings.heightNumber*-1)+zeroSet}, settings.speed, settings.easing).animate({top: zeroSet},1, 'linear');
                }else{
                    // if the new number is lower than the old, we have to go to the bottom 0 and start from the top 0, with the apropiate speed, to don't note the jump
                    if (newDigit < oldDigit){
                        col.animate({top: (10*settings.heightNumber*-1)+zeroSet}, settings.speed*((10-oldDigit)/10), 'linear').animate({top: zeroSet},1, 'linear').animate({top: (newDigit*settings.heightNumber*-1)+zeroSet}, settings.speed*oldDigit/10, settings.easing);
                    }else{
                        col.animate({top: (newDigit*settings.heightNumber*-1)+zeroSet}, settings.speed, settings.easing);
                    }
                }
            }
        }

which updates the odometer. I am using ajax to get new data, and I want to update the odometer readings. How can I call advanceCounter() or setNumbers() from my webpage, to update the odometer?

Help.

Here is a demo of the actual plugin (from the author himself). http://www.frontendmatters.com/demos/jodometer/

  • 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-29T08:02:50+00:00Added an answer on May 29, 2026 at 8:02 am

    It looks like you could just set it when you get new data like this:

    function updateTimer(newVal)
    {
        $(".myCounter").jOdometer({ counterStart: newVal, counterEnd:newVal, numbersImage: 'images/jodometer-numbers.png'});
    }
    

    I’m not sure what you would want the increment to be, if any, but this should do the trick.

    Update:

    Here it is with the built-in animation.

    Open up your jquery.jodometer.js file.
    Look at line 100 (right below the function ‘advanceCounter()’) and add this:

    $.fn.Advance = function(newVal)
    {
        setNumbers(newVal);
    }
    

    Now you can increment the counter by doing:

    $("#MyCounterDiv").Advance(150); //150  whatever new value you want.
    

    Update 2:

    I was only testing with one counter. aVC pointed out that only the last counter initialized will be affected.
    Here’s how I worked around that:

    Replace the setNumbers function with this:

    function setNumbers(counter, elem){
        digits = String(counter).split('.'); // check decimals
        // if we where using decimals
        if (decimalsArray.length > 0){
            // for each decimal digit, update the old digit position to the new
            for (i=0;i<decimalsArray.length;i++){
                oldDigit = decimalsArray[i];
                // the new numer could have not decimal part, but we need it anyway
                if (digits[1]){
                    decimalsArray[i] = digits[1].charAt(i);
                }
                if (decimalsArray[i] == ''){
                    decimalsArray[i] = '0';
                }
                var theScope = (elem) ? elem : scope;
                console.log(theScope);
                updatePosition($('.jodometer_decimal_'+i, theScope), parseInt(decimalsArray[i]), parseInt(oldDigit));
            }
        }
    
        integers = digits[0];
        j=integers.length-1;
        // for each integer digit, update the old digit position to the new
        for (i=0;i<integersArray.length;i++){
            oldDigit = integersArray[i];
            integersArray[i] = integers.charAt(j);
            if (integersArray[i] == ''){
                integersArray[i] = '0';
            }
            var theScope = (elem) ? elem : scope;
            console.log(theScope);
            updatePosition($('.jodometer_integer_'+i, theScope), parseInt(integersArray[i]), parseInt(oldDigit));
            j--;
        }
    }
    

    I added another parameter “elem” which will be passed in the Advance function we added earlier. Just need to change the $.fn.Advance function to this:

    $.fn.Advance = function(newVal)
    {
        setNumbers(newVal, $(this));
    }
    

    Finally, I found that for some reason I needed to remove an if statement from the updatePosition function. This if statement figures out if you’re trying to tell it to ‘change’ to the same number. It breaks because it checks the wrong counter’s settings. We could work around this if it’s important, but I just decided to comment it out 😛

    function updatePosition(col, newDigit, oldDigit){
        //if(newDigit != oldDigit){
            col.stop();
            // if the number is 0 use the bottom 0 in the image, and change intantly to the top 0
            if (newDigit == 0){
                col.animate({top: (10*settings.heightNumber*-1)+zeroSet}, settings.speed, settings.easing).animate({top: zeroSet},1, 'linear');
            }else{
                // if the new number is lower than the old, we have to go to the bottom 0 and start from the top 0, with the apropiate speed, to don't note the jump
                if (newDigit < oldDigit){
                    col.animate({top: (10*settings.heightNumber*-1)+zeroSet}, settings.speed*((10-oldDigit)/10), 'linear').animate({top: zeroSet},1, 'linear').animate({top: (newDigit*settings.heightNumber*-1)+zeroSet}, settings.speed*oldDigit/10, settings.easing);
                }else{
                    col.animate({top: (newDigit*settings.heightNumber*-1)+zeroSet}, settings.speed, settings.easing);
                }
            }
        //}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm fairly new to JQuery and for some reason I can't get the currently
So I'm trying to get some basic jQuery code with Rails working, but it
I'm new to jQuery and i'm trying to write some code to go through
I'm very new to JQuery, and I'm having some trouble understanding how to do
I've been trying to use the new jquery-ui, and all but the resizable function
I am trying to create some basic button rollover functionality using Jquery and toggleClass.
I'm new to javascript/jquery and I've done some poking around the web, but I
jQuery and JavaScript in general are new ground for me. What are some good
I new with jquery and I can do simple coding with it. and I
I'm brand new to jQuery (and javascript in general). I've been meaning to use

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.