-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
117 lines (113 loc) · 2.84 KB
/
demo.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
111
112
113
114
115
116
117
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="css/index.css">
<title>vue-scroller</title>
</head>
<body>
<ul id="app">
<scroller :on-infinite="infinite" :on-refresh="refresh" ref="my_scroller">
<li v-for="x in items">
<span>{{x}}</span>
<span style="float: right;padding-right: 10px">><span>
</li>
</scroller>
</ul>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="vue-scroller/vue-scroller.min.js"></script>
<script>
var fakemsg=[
"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"
];
var step=5; //定义每次刷新加载5条
var app=new Vue({
el:"#app",
mounted:function(){
for(let i=0;i<10;i++){ //先刷出10条
this.items.push(fakemsg[i])
}
this.bottom=10; //从第11条开始加载
},
data:{
items:[]
},
methods:{
refresh:function(done){
this.$refs.my_scroller.finishPullToRefresh(); //停止刷新
},
infinite:function(done){
if(this.bottom >= fakemsg.length){
setTimeout(() => {
done(true);
},1200)
// this.$refs.my_scroller.finishInfinite(true)
return;
}
setTimeout(() => {
let start=this.bottom;
for(let i = start;i < start + step;i++){
this.items.push(fakemsg[i]);
}
this.bottom = this.bottom+step;
// console.log("this.bottom",this.bottom);
setTimeout(() => {
done();
})
var cha = fakemsg.length - this.bottom;
if(cha < step){
step = cha;
}
},1200)
}
}
})
</script>
</body>
</html>