呃呃呃,具体这个效果是否是叫这个名,我不知道,本身起的名字
具体效果直接看这个地址,https://951565664.github.io/S...
我研究了半天,也没搞懂gif 怎么作的。
废话很少说了。开始正题css
----------------------------------我是分割线,线割分是我 -----------------------------
提早说明一下,demo的数据变化,是我随机产生的。。而你们用到的时候确定是正式项目需求。那么若是值不变,是不会render内部的。因此外层尽管无节操调用。全部动画都是css作的,性能应该是最优的了。react
npm install scoreboard-react --save
orgit
yarn install scoreboard-react --save
import Scoreboard from 'scoreboard';
Props | desc | type | default |
---|---|---|---|
transitionDuration | 动画的时间 | String |
0.5s |
numberStyle | 数字的样式 | Object |
{} |
style | 外框的样式 | Object |
{} |
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