MUI 上拉加載 完整實例
例子是參照網上的MUI豆瓣電影,但是android上有一個問題 上拉后卡主不能動,并且提示
Ignored attempt to cancel a touchmove event with cancelable=false
查了很多,最后解決的方案是 阻止了冒泡事件。
1
<!DOCTYPE html>
2
<html>
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
7
<title>首頁</title>
8
<script src="js/mui.min.js"></script>
9
<link href="css/mui.min.css" rel="stylesheet" />
10
<link href="css/style.css" rel="stylesheet" />
11
<style>
12
html,
13
body {
14
background-color: white;
15
}
16
17
.wrap-search {
18
margin: 15px;
19
background: #E6E6E6;
20
height: 30px;
21
border-radius: 5px;
22
text-align: center;
23
}
24
25
.item-img {
26
width: 60px;
27
height: 90px;
28
margin-right: 10px;
29
}
30
</style>
31
</head>
32
33
<body>
34
<div class="mui-content" style="background: white;">
35
<div class="wrap-search">
36
<span class="mui-icon mui-icon-search" style="line-height: 30px; color: #AAAAAA; font-size: 16px;"></span>
37
<span style="line-height: 30px; color: #AAAAAA; font-size: 14px;">電影/電視劇/影人</span>
38
</div>
39
40
<div id="refreshContainer" class="mui-scroll-wrapper" >
41
<div class="mui-scroll">
42
<ul class="mui-table-view" id="movies">
43
<li class="mui-table-view-cell" v-for="item in movies">
44
<img class="item-img mui-pull-left" :src="item.cover" />
45
<div class="mui-ellipsis dark-big">
46
{{item.title}}
47
</div>
48
<div class="mui-ellipsis ">
49
<span class="gray-small">{{ item.genres}}</span>
50
<span v-if="item.score>0" class="orange-small"> {{item.score}}分</span>
51
<span v-else class="orange-small">暫無評分</span>
52
</div>
53
54
<div class="mui-ellipsis gray-small">
55
導演:{{item.directors}}
56
</div>
57
<div class="mui-ellipsis gray-small">
58
主演:{{item.casts}}
59
</div>
60
</li>
61
62
</ul>
63
</div>
64
65
</div>
66
</div>
67
68
<script src="js/vue.min.js"></script>
69
<script src="js/util.js"></script>
70
<script type="text/javascript">
71
var data_movies = new Vue({
72
el: '#movies',
73
data: {
74
movies: []
75
}
76
});
77
78
var aniShow = {};
79
80
mui.init({
81
swipeBack: true, //啟用右滑關閉功能
82
pullRefresh: {
83
container: "#refreshContainer", //下拉刷新容器標識,querySelector能定位的css選擇器均可,比如:id、.class等
84
down: {
85
auto: false, //可選,默認false.首次加載自動上拉刷新一次
86
callback: refreshData //必選,刷新函數,根據具體業務來編寫,比如通過ajax從服務器獲取新數據;
87
},
88
up: {
89
height: 50, //可選.默認50.觸發上拉加載拖動距離
90
auto: true, //可選,默認false.自動上拉加載一次
91
contentrefresh: "正在加載
", //可選,正在加載狀態時,上拉加載控件上顯示的標題內容
92
contentnomore: '沒有更多數據了', //可選,請求完畢若沒有更多數據時顯示的提醒內容;
93
callback: loadmorData //必選,刷新函數,根據具體業務來編寫,比如通過ajax從服務器獲取新數據;
94
}
95
}
96
});
97
98
// 刷新數據 重新調用接口
99
function refreshData() {
100
// 請求熱映列表接口
101
mui.getJSON(baseUrl + 'movie/in_theaters', {
102
start: 0,
103
count: 10
104
}, function(resp) {
105
data_movies.movies.splice(0, data_movies.movies.length);
106
data_movies.movies = data_movies.movies.concat(convert(resp.subjects));
107
mui('#refreshContainer').pullRefresh().endPulldownToRefresh();
108
mui('#refreshContainer').pullRefresh().refresh(true);
109
})
110
111
}
112
113
var tatalCount = 0;
114
// 加載分頁
115
function loadmorData() {
116
if(data_movies.movies.length > tatalCount ){
117
mui.toast('我是有底線的
.');
118
return;
119
}
120
// 請求熱映列表接口
121
mui.getJSON(baseUrl + 'movie/in_theaters', {
122
start: data_movies.movies.length,
123
count: 10
124
}, function(resp) {
125
data_movies.movies = data_movies.movies.concat(convert(resp.subjects));
126
tatalCount = resp.total ;
127
mui('#refreshContainer').pullRefresh().endPullupToRefresh(data_movies.movies.length > resp.total);
128
})
129
130
}
131
132
mui.plusReady(function() {
133
var self = plus.webview.currentWebview(),
134
nviews = self.getSubNViews(),
135
subpages = util.options.subpages;
136
// 創建子webview窗口 并初始化
137
util.initSubpage(aniShow);
138
activePage = plus.webview.currentWebview();
139
140
//給每個view 添加監聽點擊切換
141
for(var i = 0; i < 3; i++) {
142
nviews[i].addEventListener('click', clickEvent, false);
143
}
144
145
// 自定義 tab 點擊事件
146
function clickEvent(e) {
147
var currId = e.target.id,
148
currIndex = parseInt(currId.substr(currId.length - 1, 1) - 1),
149
currView = self.getStyle().subNViews[currIndex];
150
// 匹配對應tab窗口
151
if(currIndex > 0) {
152
targetPage = plus.webview.getWebviewById(subpages[currIndex - 1]);
153
154
} else {
155
targetPage = plus.webview.currentWebview();
156
}
157
158
if(targetPage == activePage) {
159
return;
160
}
161
162
if(currIndex !== 3) {
163
//底部選項卡切換
164
util.toggleNview(currView, currIndex);
165
// 子頁面切換
166
util.changeSubpage(targetPage, activePage);
167
//更改當前活躍的頁面
168
activePage = targetPage;
169
}
170
}
171
172
173
174
});
175
176
// 添加點擊事件
177
178
mui('.wrap-search')[0].addEventListener('tap', function() {
179
console.log('click
.0')
180
})
181
182
mui('.mui-scroll-wrapper').scroll({
183
indicators: false
184
});
185
186
mui('.mui-scroll-wrapper')[0].addEventListener('touchmove', function (e) {
187
e.stopPropagation();
188
});
189
//
190
// function buffer(fn, ms) {
191
// var timeout;
192
// return function() {
193
// if (timeout) return;
194
// var args = arguments;
195
// timeout = setTimeout(function() {
196
// timeout = null;
197
// fn.apply(null, args);
198
// }, ms);
199
// }
200
// }
201
//
202
// document.querySelector('.mui-scroll-wrapper').onScroll = buffer(onScroll, 100);
203
204
205
206
// 數據轉換
207
function convert(items) {
208
var newItems = [];
209
210
items.forEach(function(item) {
211
var genres = item.genres.toString().replace(/,/g, '/');
212
// 導演
213
var directors = '';
214
for(var i = 0; i < item.directors.length; i++) {
215
directors += item.directors[i].name;
216
if(i != item.directors.length - 1) {
217
directors += ' / ';
218
}
219
220
}
221
222
// 演員
223
var casts = '';
224
for(var i = 0; i < item.casts.length; i++) {
225
casts += item.casts[i].name;
226
if(i != item.casts.length - 1) {
227
casts += ' / ';
228
}
229
230
}
231
232
newItems.push({
233
id: item.id,
234
title: item.title,
235
genres: genres,
236
cover: item.images.large,
237
score: item.rating.average,
238
directors: directors,
239
casts: casts
240
})
241
242
})
243
244
return newItems;
245
}
246
</script>
247
</body>
248
249
</html>

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


118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179


180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249
