Giter Site home page Giter Site logo

bby422 / arc-counter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bloveless/arc-counter

0.0 1.0 0.0 96 KB

A native canvas javascript plugin for counting to a number with an animated arc around the number.

CSS 1.97% HTML 9.01% JavaScript 89.02%

arc-counter's Introduction

ArcCounter

A native canvas javascript plugin for counting to a number with an animated arc around the number.

An example is provided in index.html so you can see the animation, but here is a screenshot so you can see a quick example.

Example Arc Counters

Installation

Add the script and css file to your page. The css is not necessary, but it will leave placeholders for your counters while the page is loading. Otherwise the counters will be have 0 height and then get a height after the counter load, causing the page to jerk a little bit.

<script src="js/arc-counter.js"></script>
<link rel="stylesheet" href="css/arc-counter.css">

It's best to add the script to the footer since there is no document ready function in it.

Then the most basic way to get started is to add the ArcCounter call after you've included the js file.

<script>
    new ArcCounter();
</script>

Now we will add the html for the counters.

<div class="arc-counter" data-number="65" data-max="100" data-text="Current Employees"></div>

Most of the data for the counters come from these data attributes.

  • data-number: is the number that is being counted to.
  • data-max: is the maximum number represented by the counter. This is used to determine how far the arc around the counter should go.
  • data-text: is the text that will be displayed below the counter.
  • data-background: is the entire background color of the canvas, but by default the canvas is transparent so you can just color the containing element however you'd like and the canvas will show that.

But, there are also some attributes you can add to the ArcCounter initialization that will be applied to all the counter.

The defaults are presented below.

    var defaults = {
        selector: '.arc-counter',
        strokeColor: '#fff',
        fillColor: 'rgba(0, 0, 0, 0.1)',
        textColor: '#000',
        fontFace: 'Calibri',
        duration: 3000,
        easingFunction: 'easeInOutQuint',
        responsive: true,
		onlyAnimateOnVisible: true
    };
  • selector: is the css selector for your counters. If you change this you can change the css to reflect your counter class. Or omit the css either will work.
  • strokeColor: is the color of the arc
  • fillColor: is the color of the circle behind the arc
  • textColor: is the color of the text inside the circle
  • fontFace: is the font you wish to use for the counter and text
  • duration: is how long it takes for the counter to finish counting
  • easingFunction: is the function you want to use when drawing the arc. All the easing functions come from this gist Easing Functions so you can use any function name from that gist.
  • responsive: if true will attache a resize event to the window so the arcs are always 100% of their container.
  • onlyAnimateOnVisible: if set to true the counters will only start their animation when they are scolled into view.

You can set one or many options as follows:

<script>
    new ArCounter({
        strokeColor: '#a90d2c',
        fontFace: 'Lato'
    });
</script>

The previous options will create a counter that has a red stroke and uses Lato for the text.

arc-counter's People

Contributors

bloveless avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.