Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Don't know about plugins but this shouldn't be too hard:</p> <pre><code>;(function($) { $.fn.counter = function(options) { // Set default values var defaults = { start: 0, end: 10, time: 10, step: 1000, callback: function() { } } var options = $.extend(defaults, options); // The actual function that does the counting var counterFunc = function(el, increment, end, step) { var value = parseInt(el.html(), 10) + increment; if(value &gt;= end) { el.html(Math.round(end)); options.callback(); } else { el.html(Math.round(value)); setTimeout(counterFunc, step, el, increment, end, step); } } // Set initial value $(this).html(Math.round(options.start)); // Calculate the increment on each step var increment = (options.end - options.start) / ((1000 / options.step) * options.time); // Call the counter function in a closure to avoid conflicts (function(e, i, o, s) { setTimeout(counterFunc, s, e, i, o, s); })($(this), increment, options.end, options.step); } })(jQuery); </code></pre> <p>Usage:</p> <pre><code>$('#foo').counter({ start: 1000, end: 4500, time: 8, step: 500, callback: function() { alert("I'm done!"); } }); </code></pre> <p>Example:</p> <blockquote> <p><a href="http://www.ulmanen.fi/stuff/counter.php" rel="noreferrer">http://www.ulmanen.fi/stuff/counter.php</a></p> </blockquote> <p>I guess the usage is self-explanatory; in this example, the counter will start from 1000 and count up to 4500 in 8 seconds in 500ms intervals, and will call the callback function when the counting is done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload