• Stars
    star
    715
  • Rank 63,327 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 12 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A jQuery plugin that will count up (or down) to a target number at a specified speed.

jQuery countTo Plugin

jQuery countTo is a jQuery plugin that will count up (or down) to a target number at a specified speed, rendered within an HTML DOM element.

Requirements:

jQuery countTo requires the latest version of jQuery.

Usage:

There are two main approaches to using this plugin: through data attributes on DOM nodes, and through JS options explicitly passed to the countTo function.

These two methods can be mixed and matched as well. Data attributes takes precedence over JS options.

Data Attributes

This approach allows you to define data-* attributes on whatever DOM element will act as a container for your counter. This is useful when you already know the values at the time that you are constructing the DOM.

<span class="timer" data-from="25" data-to="75"></span>

<script type="text/javascript">
  $('.timer').countTo();
</script>

A more detailed example that demonstrates all possible options being used is as follows.

<span class="timer" data-from="0" data-to="100"
      data-speed="5000" data-refresh-interval="50"></span>

<script type="text/javascript">
  $('.timer').countTo();
</script>

Refer to the Options section below for more info on the various options available.

JavaScript Options

This approach allows you to pass values to the countTo function. This is useful when you don't know the values at the time the DOM is being rendered.

<span class="timer"></span>

<script type="text/javascript">
  $('.timer').countTo({from: 0, to: 500});
</script>

A more detailed example that demonstrates all possible options being used is as follows.

<span class="timer"></span>

<script type="text/javascript">
  $('.timer').countTo({
    from: 50,
    to: 2500,
    speed: 1000,
    refreshInterval: 50,
    formatter: function (value, options) {
      return value.toFixed(options.decimals);
    },
    onUpdate: function (value) {
      console.debug(this);
    },
    onComplete: function (value) {
      console.debug(this);
    }
  });
</script>

Refer to the Options section below for more info on the various options available.

Options:

A complete listing of the options that can be passed to the countTo method is below.

Option Data Attribute Description
from data-from The number to start counting from. (default: 0)
to data-to The number to stop counting at. (default: 100)
speed data-speed The number of milliseconds it should take to finish counting. (default: 1000)
refreshInterval data-refresh-interval The number of milliseconds to wait between refreshing the counter. (default: 100)
decimals data-decimals The number of decimal places to show when using the default formatter. (default: 0)
formatter (value, options) A handler that is used to format the current value before rendering to the DOM. The true current value and options set is passed to the function, and it is run in the context of the DOM element. It must return the formatted value. (default: value.toFixed(options.decimals))
onUpdate (value) A callback function that is triggered for every iteration that the counter updates. The currently rendered value is passed to the function, and it is called in the context of the DOM element. (default: null)
onComplete (value) A callback function that is triggered when counting finishes. The final rendered value is passed to the function, and it is called in the context of the DOM element. (default: null)

Functions:

This plugin also supports functions, primarily for changing state. Functions are called by passing the name as a string to the countTo jQuery function, e.g.: $('#timer').countTo('stop').

start Resumes the timer if it is stopped.
stop Stops (pauses) the timer if it is running.
toggle Starts or stops the timer based upon its current state.
restart Restarts the timer at its initial "from" value.

Created By:

Matt Huggins

License:

jQuery-countTo is released under the MIT license.

More Repositories

1

ruby-measurement

Simple Ruby gem for calculating and converting measurements.
Ruby
45
star
2

a2z

Simple Ruby DSL for searching & retrieving items from the Amazon Product Advertising API
Ruby
41
star
3

multiple_table_inheritance

Multiple Table Inheritance is a plugin designed to allow for multiple table inheritance between your database tables and your ActiveRecord models.
Ruby
30
star
4

dogeify

Ruby gem for converting English to Doge.
Ruby
28
star
5

dominatrix

Parse the registered domain name from a URL.
Ruby
19
star
6

ruby-dictionary

Dictionary class for ruby that allows for checking existence and finding words starting with a given prefix.
Ruby
11
star
7

socket.io-cookie-parser

Cookie parser middleware for your socket.io or engine.io app.
JavaScript
10
star
8

net-rtmp

Ruby Net::RTMP client
Ruby
9
star
9

jquery-ui-autocomplete-hints

An extension for jQuery UI Autocomplete to provide visual hints to the user that this field is actually doing something when you type.
JavaScript
9
star
10

intent

Titanium module that allows getStringArrayListExtra to be called on an intent
Python
6
star
11

domainator

Parse the registered domain name from a URL.
Ruby
6
star
12

railway-bootstrap

Render Twitter Bootstrap HTML forms with RailwayJS models
JavaScript
3
star
13

supermarket_api

Ruby client for the Supermarket API
Ruby
2
star
14

simple_form_autocomplete

Ruby autocomplete for SimpleForm form fields
Ruby
2
star
15

formtastic_autocomplete

Ruby autocomplete for Formtastic form fields
Ruby
1
star
16

sequelize-middleware

Sequelize middleware for your Express or Connect app.
JavaScript
1
star
17

lol_client

Ruby client for Riot's League of Legends REST API
Ruby
1
star