forked from Kenshin/simpread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressbar.jsx
More file actions
36 lines (28 loc) · 1.02 KB
/
progressbar.jsx
File metadata and controls
36 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
console.log( "==== simpread read component: ProcessBar ====" )
export default class ProcessBar extends React.Component {
static defaultProps = {
show : true,
offset: document.documentElement.scrollTop / ( document.documentElement.scrollHeight - document.documentElement.clientHeight ) || 0
}
state = {
progress: this.props.offset
}
componentDidMount() {
setTimeout( ()=>{
$( document ).on( "scroll", ()=>this.scrollEventHandle() );
}, 1000 );
}
componentWillUnmount() {
$( document ).off( "scroll", this.scrollEventHandle() );
}
scrollEventHandle() {
const offset = document.documentElement.scrollTop / ( document.documentElement.scrollHeight - document.documentElement.clientHeight );
this.setState({ progress: offset });
}
render() {
const progress = this.state.progress * 100;
return (
this.props.show && <read-process style={{ "width": `${progress}%` }}></read-process>
)
}
}