/
index.html
110 lines (101 loc) · 2.32 KB
/
index.html
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<script src="https://unpkg.com/vue@2.2.6/dist/vue.min.js"></script>
<script src="../vue-scroller.min.js"></script>
<title>Vue Scroller</title>
<style>
html, body {
margin: 0;
}
* {
box-sizing: border-box;
}
.row {
width: 100%;
height: 50px;
padding: 10px 0;
font-size: 16px;
line-height: 30px;
text-align: center;
color: #444;
background-color: #fff;
}
.grey-bg {
background-color: #eee;
}
.header {
position: fixed;
top: 0;
left: 0;
height: 44px;
width: 100%;
box-shadow: 0 2px 10px 0 rgba(0,0,0,0.1);
background-color: #fff;
z-index: 1000;
color: #666;
}
.header > .title {
font-size: 16px;
line-height: 44px;
text-align: center;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="app">
<div class="header">
<h1 class="title">Refresh & Infinite</h1>
</div>
<scroller :on-refresh="refresh"
:on-infinite="infinite"
style="padding-top: 44px;">
<div v-for="(item, index) in items" class="row" :class="{'grey-bg': index % 2 == 0}">
{{ item }}
</div>
</scroller>
</div>
<script>
new Vue({
el: '#app',
data: {
items: []
},
mounted: function () {
for (var i = 1; i <= 20; i++) {
this.items.push(i + ' - keep walking, be 2 with you.');
}
this.top = 1;
this.bottom = 20;
},
methods: {
refresh: function (done) {
var self = this
setTimeout(function () {
var start = self.top - 1
for (var i = start; i > start - 10; i--) {
self.items.splice(0, 0, i + ' - keep walking, be 2 with you.');
}
self.top = self.top - 10;
done();
}, 1500)
},
infinite: function (done) {
var self = this
setTimeout(function () {
var start = self.bottom + 1;
for (var i = start; i < start + 10; i++) {
self.items.push(i + ' - keep walking, be 2 with you.');
}
self.bottom = self.bottom + 10;
done();
}, 1500)
}
}
});
</script>
</body>
</html>