forked from schovi/react-iscroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.jsx
93 lines (80 loc) · 2.25 KB
/
example.jsx
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require('./example.css')
var React = require('react')
var ReactIScroll = require('../index.js')
var IScroll = require('iscroll')
var iScrollOptions = {
mouseWheel: true,
scrollbars: true
}
var Example = React.createClass({
getInitialState: function() {
var list = [], i = 0, len = 30;
for(i; i < len; i++) {
list.push(i+1)
}
return {
y: 0,
isScrolling: false,
list: list,
lastId: len
}
},
onScrollStart: function() {
this.setState({isScrolling: true})
},
onScrollEnd: function(iscroll) {
this.setState({isScrolling: false, y: iscroll.y})
},
addRow: function(ev) {
ev.preventDefault()
var list = this.state.list,
newId = this.state.lastId + 1;
list.push(newId)
this.setState({list: list, lastId: newId})
},
removeRow: function(ev) {
ev.preventDefault()
var list = this.state.list;
list.shift()
this.setState({list: list})
},
onScrollRefresh: function(iscroll) {
var hasVerticalScroll = iscroll.hasVerticalScroll
if(this.state.canScroll !== hasVerticalScroll) {
this.setState({canScroll: hasVerticalScroll})
}
},
render: function() {
var i = 0,
len = this.state.list.length,
listOfLi = [];
for(i; i < len; i++) {
listOfLi.push(<li key={i}>Pretty row {this.state.list[i]}</li>)
}
return (
<div>
<div id="header">
<button onClick={this.removeRow} className="button">Remove first row</button>
React IScroll component example
</div>
<div id="wrapper">
<ReactIScroll iscroll={IScroll}
options={iScrollOptions}
onRefresh={this.onScrollRefresh}
onScrollStart={this.onScrollStart}
onScrollEnd={this.onScrollEnd}>
<ul>
{listOfLi}
</ul>
</ReactIScroll>
</div>
<div id="footer">
<button onClick={this.addRow} className="button">Add one row</button>
status: {this.state.isScrolling ? 'Scrolling' : 'Standby' } |
can scroll: {this.state.canScroll ? 'Yes' : 'No'}
</div>
</div>
)
}
})
React.render(<Example />, document.getElementById("example"))