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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:50:51+00:00 2026-05-25T21:50:51+00:00

I have a peice of code that counts from 0 to a specified number

  • 0

I have a peice of code that counts from 0 to a specified number and displays it while it is counting.
The problem is that I want to use the code in a web app that is made using jQuery mobile.
When the code is used with normal html i works fine, but when I use it with jQuery mobile it wont work.
I dont want the number to start counting until a certain mobile page is loaded, is there a way to do this??
I think the problem is because in jquery mobile all of the pages are contained within one html document and the number sarts counting when the html page is open and I want it to start when the ‘#about’ section is displayed?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
$(function() {
    $('#foo').counter({
        start: 1000,
        end: 400000,
        time: 1,
        step: 50,
        callback: function() {
            $("#foo").html("400000");
        }
    });
});

;(function($) {        
     $.fn.counter = function(options) {


        var options   = $.extend(defaults, options);

        var counterFunc = function(el, increment, end, step) {
            var value = parseInt(el.html(), 10) + increment;
            if(value >= end) {
                el.html(Math.round(end));
                options.callback();
            } else {
                el.html(Math.round(value));
                setTimeout(counterFunc, step, el, increment, end, step);
            }
        }

        $(this).html(Math.round(options.start));
        var increment = (options.end - options.start) / ((1000 / options.step) * options.time);

        (function(e, i, o, s) {
            setTimeout(counterFunc, s, e, i, o, s);
        })($(this), increment, options.end, options.step);
    }
})(jQuery);
    </script>
    <style type="text/css">
    </style>
</head>

<body>
    <span id="foo"></span>
</body>
</html>
  • 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-25T21:50:52+00:00Added an answer on May 25, 2026 at 9:50 pm

    Check-out the events documentation for jQuery Mobile: http://jquerymobile.com/demos/1.0rc1/docs/api/events.html.

    Rather than running your code on document.ready you want to run it on pageshow.

    Change:

    $(function() {
        $('#foo').counter({
            start: 1000,
            end: 400000,
            time: 1,
            step: 50,
            callback: function() {
                $("#foo").html("400000");
            }
        });
    });
    

    To:

    $(document).delegate('#about', 'pageshow', function() {
        $('#foo').counter({
            start: 1000,
            end: 400000,
            time: 1,
            step: 50,
            callback: function() {
                $("#foo").html("400000");
            }
        });
    });
    

    I have not used the “counter” plugin so I’m not sure how to do it but you may want to stop the counter when the user navigates to another page, to do so just bind whatever code stops the counter to the pagehide event:

    $(document).delegate('#about', 'pagehide', function () {
        //code to stop counter goes here
    });
    

    A NOTE: I use the .delegate() function in the examples above which when used on the $(document) object acts like the .live() function:

    $(document).delegate('#about', 'event-name', function () {}); is similar to $(#about).live('event-name', function () {}); however .delegate() performs more efficiently. Documentation for delegate is here: http://api.jquery.com/delegate/

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

Sidebar

Related Questions

I have a piece of code that takes several rows from a database and
If have a piece of code that gets some data from a sql database
i have this piece of code that selects all users from the table and
I currently have code that reads a recording in from the devices mic using
I have this piece of code that does not work: public CartaoCidadao() { InitializeComponent();
I have this piece of code that works fine in subsonic 2.2, I migrated
I have a piece of code that load a very big image in memory.
I have a piece of code that look similar to this: <xsl:choose> <xsl:when test=some_test>
I have a piece of code that calls a WCF service that is hosted
I have a piece of code that converts an infix expression to an expression

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.