一個react的關於統計數字的動畫---Scoreboard

呃呃呃,具體這個效果是否是叫這個名,我不知道,本身起的名字
具體效果直接看這個地址,https://951565664.github.io/S...
我研究了半天,也沒搞懂gif 怎麼作的。
廢話很少說了。開始正題css

----------------------------------我是分割線,線割分是我 -----------------------------
提早說明一下,demo的數據變化,是我隨機產生的。。而你們用到的時候確定是正式項目需求。那麼若是值不變,是不會render內部的。因此外層儘管無節操調用。全部動畫都是css作的,性能應該是最優的了。react

Scoreboard


Install

npm install scoreboard-react --save

orgit

yarn install scoreboard-react --save

Usage

import Scoreboard from 'scoreboard';

Props

Props desc type default
transitionDuration 動畫的時間 String 0.5s
numberStyle 數字的樣式 Object {}
style 外框的樣式 Object {}

Demo

D:codeSpaceScoreboardexampletestgithub

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import Scoreboard from 'scoreboard-react';
import styles from './index.less'

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
class App extends Component {
    state = {
        key: 2
    }
    changeNum = (params) => {
        this.setState({
            key: parseInt(Math.random() * 10) + 2
        })
    }
    componentDidMount = () => {
        this.timer = setInterval(this.changeNum, 1000)
    }
    componentWillMount = () => {
        clearInterval(this.timer)
    }

    render() {
        let numberStr = new Array(this.state.key).fill(1).map((item) => parseInt(Math.random() * 10)).reduce((prev, curr, index, array) => '' + prev + curr);
        return (
            <div className={styles["wrapper"]}>
                <div className={styles.forkMe} >
                    <a href="https://github.com/951565664/Scoreboard" target="_">
                        <img
                            src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67"
                            alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"
                        />
                    </a>
                </div>
                <div onClick={this.changeNum} style={{ width: '100%' }}>
                    <Scoreboard numberStr={numberStr} transitionDuration={'1s'} numberStyle={{ color: '#c40000', fontSize: '20px' }} />
                </div>
            </div>
        );
    }
}
ReactDOM.render(<App />, document.getElementById('root'));

demo的數據變化,是我隨機產生的。。而你們用到的時候確定是正式項目需求。那麼若是值不變,是不會render內部的。因此外層儘管無節操調用。npm

若是你們有任何關於這個動畫擴展的需求能夠直接提的。我儘可能第一時間反饋,畢竟我是以掙star爲目的的,哈哈哈哈bash

相關文章
相關標籤/搜索