GithubHelp home page GithubHelp logo

zhans1993 / react-countup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from glennreyes/react-countup

0.0 0.0 0.0 4.46 MB

๐Ÿ’ซ A configurable React component wrapper around CountUp.js

Home Page: https://glennreyes.github.io/react-countup

License: MIT License

JavaScript 100.00%

react-countup's Introduction

Build Status Coverage Status Dependency Status Dependency Status npm version

A configurable React component wrapper around CountUp.js.

sep -15-2016 10-11-53 pm

Check out the demo.

Installation

yarn add react-countup

Alternatively with npm:

npm install react-countup --save

Usage

Simple

import React from 'react';
import { render } from 'react-dom';
import CountUp from 'react-countup';

render(
  <CountUp start={0} end={160526} />,
  document.getElementById('root')
);

Advanced

import React from 'react';
import { render } from 'react-dom';
import CountUp from 'react-countup';

const onComplete = () => {
  console.log('Completed! ๐Ÿ‘');
};

const onStart = () => {
  console.log('Started! ๐Ÿ’จ');
};

render(
  <CountUp
    className="account-balance"
    start={160527.0127}
    end={-875.0319}
    duration={2.75}
    useEasing={true}
    useGrouping={true}
    separator=" "
    decimals={4}
    decimal=","
    prefix="EUR "
    suffix=" left"
    onComplete={onComplete}
    onStart={onStart}
  />,
  document.getElementById('root'),
);

Props

start: number

Start value

end: number

Target value

duration: number

Duration in seconds

decimals: number

Amount of decimals

useEasing: boolean

Enable easing if set to true (default easing: easeOutExpo)

separator: string

Specifies character of thousands separator

decimal: string

Specifies decimal character

prefix: string

Static text before the animating value

suffix: string

Static text after the animating value

className: string

CSS class name of the span element

redraw: boolean

If set to true, the CountUp component will always animate on every re-render.

onComplete: function

Function called after animation has completed

onStart: function

Function called before animation starts

easingFn: function

Easing function, see here for instructions

formattingFn: function

Function to customize the formatting of the number

Protips

By default, the animation is triggered if any of the following props has changed:

  • duration
  • end
  • start

You can set redraw to true If you want your component to always animate on every re-render.

Manually start the animation

import React, { Component } from 'react';
import CountUp, { startAnimation } from 'react-countup';

const MyComponent = () => (
  <div>
    <CountUp className="CountUp" start={0} end={100} duration={3} ref={(countUp) => {
      this.myCountUp = countUp;
    }} />
    <button className="Button" onClick={(event) => {
      startAnimation(this.myCountUp);
    }}>Count me up!</button>
  </div>
);

export default App;

License

MIT

react-countup's People

Contributors

alexlukelevy avatar booxood avatar gayancharith avatar glennreyes avatar greenkeeper[bot] avatar greenkeeperio-bot avatar stern-shawn avatar tomkelsey avatar tutv 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.