Skip to content

Commit 5d58fe8

Browse files
committed
update
1 parent edd53c9 commit 5d58fe8

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
lines changed

README.en.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# react-scroll-log-text
2+
3+
> 这是一个react文字滚动插件
4+
5+
[![NPM](https://img.shields.io/npm/v/react-scroll-log-text.svg)](https://www.npmjs.com/package/react-scroll-log-text) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
6+
7+
[Document](README.en.md)
8+
9+
## 安装
10+
11+
```bash
12+
npm install --save react-scroll-log-text // or yarn add react-scroll-log-text
13+
```
14+
15+
## 使用
16+
17+
```jsx
18+
import React, { Component } from 'react'
19+
20+
import MyComponent from 'react-scroll-log-text'
21+
import 'react-scroll-log-text/dist/index.css'
22+
23+
class Example extends Component {
24+
render() {
25+
return <MyComponent />
26+
}
27+
}
28+
```
29+
30+
## Props
31+
32+
Available props for component:
33+
34+
|Name|Descr|Default|
35+
|---|---|---|
36+
| `speed` | Set the animation speed (0-100) | 100 |
37+
38+
## License
39+
40+
MIT © [rfw](https://github.com/rfw)

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
# react-scroll-log-text
22

3-
> This is a React log text scrolling component.
3+
> 这是一个react文字滚动插件
44
55
[![NPM](https://img.shields.io/npm/v/react-scroll-log-text.svg)](https://www.npmjs.com/package/react-scroll-log-text) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
66

7-
## Install
7+
[Document](README.en.md)
8+
9+
<img src="example/demo.gif">
10+
![alt text](https://github.com/rfw/react-scroll-log-text/blob/main/example/demo.gif?raw=true)
11+
12+
## 安装
813

914
```bash
10-
npm install --save react-scroll-log-text
15+
npm install --save react-scroll-log-text // or yarn add react-scroll-log-text
1116
```
1217

13-
## Usage
18+
## 使用
1419

1520
```jsx
1621
import React, { Component } from 'react'
@@ -25,6 +30,18 @@ class Example extends Component {
2530
}
2631
```
2732

33+
## 参数
34+
35+
|字段|描述|类型|默认值|
36+
|---|---|---|---|
37+
| `data` | 数据 | Array or Object | [] |
38+
| `animateSpeed` | 动画滚动过渡时间,单位:秒 | Number | 1 |
39+
| `length` | 大于length条数据开始滚动 | Number | 5 |
40+
| `liStyle` | li标签的sytle (像素必须加单位px) | Object | |
41+
| `childrenFc` | 自定义渲染item组件,如data为多个字段时 | function | |
42+
43+
举个例子:[example](example)
44+
2845
## License
2946

3047
MIT © [rfw](https://github.com/rfw)

example/demo.gif

158 KB
Loading

example/src/App.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ import ScrollText from 'react-scroll-log-text'
44
import 'react-scroll-log-text/dist/index.css'
55

66
const App = () => {
7-
const [data, setData ] = useState(['aaaa','bbbbb', 'ccc', 'dddd']); // 默认数据
7+
const [data, setData ] = useState(['aaaa','bbbbb', 'cccc', 'dddd']); // 默认数据
88

9-
useEffect(() =>{
9+
// Simulate update data
10+
useEffect(() =>{
1011
setInterval(()=> {
1112
const arr = [Math.random()];
12-
setData(arr)
13+
setData(arr) // update one data
1314
}, 3000);
1415
}, [])
1516

16-
return <ScrollText data={data} length={4} liStyle={{lineHeight: '40px'}} childrenFc={(v) => <div>={v}=</div>}/>
17+
return <ScrollText
18+
data={data}
19+
length={4}
20+
liStyle={{lineHeight: '40px'}}
21+
childrenFc={(v) => <div>={v}=</div>}
22+
/>
1723
}
1824

1925
export default App

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default class ScrollText extends React.Component {
66
constructor(props) {
77
super(props)
88
this.state = {
9-
data: props.data,
9+
data: props.data || [],
1010
marginTop: '0',
1111
animate: false
1212
}
@@ -69,7 +69,7 @@ export default class ScrollText extends React.Component {
6969
id={styles.scrollList}
7070
style={
7171
animate
72-
? { transition: ` margin ${animateSpeed || 1}s`, marginTop }
72+
? { transition: ` margin ${animateSpeed}s`, marginTop }
7373
: { marginTop }
7474
}
7575
>
@@ -90,3 +90,8 @@ ScrollText.propTypes = {
9090
data: PropTypes.array.isRequired, // 数据
9191
childrenFc: PropTypes.func // 自定义渲染item
9292
}
93+
94+
ScrollText.defaultProps = {
95+
animateSpeed: 1,
96+
length: 5
97+
}

0 commit comments

Comments
 (0)