-
Notifications
You must be signed in to change notification settings - Fork 486
Expand file tree
/
Copy pathscroll.js
More file actions
62 lines (54 loc) · 1.61 KB
/
scroll.js
File metadata and controls
62 lines (54 loc) · 1.61 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { Component } from 'react';
import LazyLoad from '../../src/';
import Widget from '../components/Widget';
import Operation from '../components/Operation';
import { uniqueId } from '../utils';
export default class Scroll extends Component {
constructor() {
super();
const id = uniqueId();
this.state = {
arr: Array.apply(null, Array(20)).map((a, index) => ({
uniqueId: id,
once: [6, 7].indexOf(index) > -1
}))
};
}
handleClick() {
const id = uniqueId();
this.setState({
arr: this.state.arr.map(el => ({ ...el, uniqueId: id }))
});
}
handleQuickJump(index, e) {
if (e) {
e.preventDefault();
}
const nodeList = document.querySelectorAll('.widget-list .widget-wrapper');
if (nodeList[index]) {
window.scrollTo(0, nodeList[index].getBoundingClientRect().top + window.pageYOffset);
}
}
render() {
return (
<div className="wrapper">
<Operation type="scroll" onClickUpdate={::this.handleClick} />
<div className="quick-jump">
<h4>Quick jump to: </h4>
{this.state.arr.map((el, index) => (
<a onClick={this.handleQuickJump.bind(this, index)} key={index}>{index + 1}</a>
))}
</div>
<div className="widget-list">
{this.state.arr.map((el, index) => (
<div className="widget-wrapper" key={index}>
<LazyLoad once={el.once} height={200}>
<Widget once={el.once} id={el.uniqueId} count={ index + 1 } />
</LazyLoad>
</div>
))}
</div>
</div>
);
}
}