forked from onlyhom/mobile-select
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
331 lines (300 loc) · 9.24 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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>mobileSelect Demo</title>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="wap-font-scale" content="no">
<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1,user-scalable=no">
<meta name="keywords" content="">
<meta name="description" content="">
<link rel="stylesheet" type="text/css" href="css/public.css">
<!-- 引入样式和js文件 -->
<link rel="stylesheet" type="text/css" href="css/mobileSelect.css">
<script src="js/mobileSelect.js" type="text/javascript"></script>
</head>
<body>
<div class="contain">
<div class="fixWidth">
<div class="nav">
<h1>mobileSelect Demo</h1>
</div>
<div class="demo">
<div id="trigger1">单项选择</div>
<div id="trigger2">双项选择</div>
<div id="trigger3">多项选择</div>
<div id="trigger4">地区选择-级联</div>
<div id="trigger5">车型选择-级联</div>
</div>
</div>
</div>
<script type="text/javascript">
var weekdayArr=['周日','周一','周二','周三','周四','周五','周六'];
var timeArr = ['08:30','09:00','09:30','10:00','10:30','11:00','11:30','12:00','12:30','13:00','13:30','14:00','14:30','15:00','15:30','16:00','16:30','17:00','17:30','18:00','18:30','19:00','19:30','20:00','20:30','21:00'];
var numArr=['1','2','3','4','5'];
var UplinkData =
[
{id:'1',value:'兰博基尼'},
{
id:'2',
value:'劳斯莱斯',
childs:[
{
id:'1',
value:'曜影'
},
{
id:'2',
value:'幻影',
childs:[
{
id:'1',
value:'标准版'
},
{
id:'2',
value:'加长版'
},
{
id:'3',
value:'巅峰之旅'
},
{
id:'4',
value:'流光熠世'
},
{
id:'5',
value:'都会典藏版'
}
]
},
{
id:'3',
value:'古思特',
childs:[
{
id:'1',
value:'加长版'
},
{
id:'2',
value:'永恒之爱'
},
{
id:'3',
value:'英骥'
},
{
id:'4',
value:'阿尔卑斯典藏版'
}
]
},
{
id:'4',
value:'魅影',
childs:[
{
id:'1',
value:'标准版'
},
{
id:'2',
value:'Black Badge'
}
]
}
]
},
{
id:'3',
value:'宾利',
childs:[
{
id:'1',
value:'慕尚',
childs:[
{
id:'1',
value:'标准版'
},
{
id:'2',
value:'极致版'
}
]
},
{
id:'2',
value:'欧陆',
childs:[
{
id:'1',
value:'尊贵版'
},
{
id:'2',
value:'敞篷标准版'
},
{
id:'3',
value:'敞篷尊贵版'
}
]
}
]
},
{
id:'4',
value:'法拉利',
childs:[
{
id:'1',
value:'LaFerrari'
},
{
id:'2',
value:'法拉利488'
},
{
id:'3',
value:'GTC4Lusso'
}
]
},
{
id:'5',
value:'玛莎拉蒂',
childs:[
{
id:'1',
value:'总裁'
},
{
id:'2',
value:'玛莎拉蒂GT'
},
{
id:'3',
value:'Levante'
}
]
}
];
//----------------------------------------------------------
//更多参数详情可查看文档 https://github.com/onlyhom/mobileSelect.js
/**
* 参数说明
* @param trigger(必填参数) 触发对象的id/class/tag
* @param wheels(必填参数) 数据源,需要显示的数据
* @param title 控件标题
* @param position 初始化定位
* @param callback 选择成功后触发的回调函数,返回indexArr(选中的选项索引)、data(选中的数据)
* @param transitionEnd 每一次手势滑动结束后触发的回调函数,返回indexArr(当前选中的选项索引)、data(选中的数据)
* @param keyMap 字段名映射
*/
/**
* 函数说明(实例化之后才可用)
* @function setTitle() 参数 string 设置控件的标题
* @function updateWheel() 参数 sliderIndex, data 重新渲染指定的轮子(可用于先实例化,后通过ajax获取数据的场景)
* @function updateWheels() 参数 data 重新渲染所有轮子,仅限级联数据格式使用(可用于先实例化,后通过ajax获取数据的场景)
* @function locatePosition() 参数 sliderIndex, posIndex 传入位置数组,重定位轮子的位置
* @function show() 参数 无参 唤起弹窗组件
* @function getValue() 参数 无参 获取组件选择的值
*/
var mobileSelect1 = new MobileSelect({
trigger: '#trigger1',
title: '单项选择',
wheels: [
{data: weekdayArr}
],
position:[2], //初始化定位 打开时默认选中的哪个 如果不填默认为0
transitionEnd:function(indexArr, data){
//console.log(data);
},
callback:function(indexArr, data){
console.log(data);
}
});
var mobileSelect2 = new MobileSelect({
trigger: '#trigger2',
title: '双项选择',
wheels: [
{data: weekdayArr},
{data: timeArr}
],
position:[1, 2],
transitionEnd:function(indexArr, data){
//console.log(data);
},
callback:function(indexArr, data){
console.log(data);
}
});
var mobileSelect3 = new MobileSelect({
trigger: '#trigger3',
title: '多项选择',
wheels: [
{data: numArr},
{data: numArr},
{data: numArr},
{data: numArr},
{data: numArr}
],
position:[0, 1, 0, 1, 0],
transitionEnd:function(indexArr, data){
//console.log(data);
},
callback:function(indexArr, data){
console.log(data);
}
});
var mobileSelect4 = new MobileSelect({
trigger: '#trigger4',
title: '地区选择',
wheels: [
{data:[
{
id:'1',
value:'附近',
childs:[
{id:'1',value:'1000米'},
{id:'2',value:'2000米'},
{id:'3',value:'3000米'},
{id:'4',value:'5000米'},
{id:'5',value:'10000米'}
]
},
{id:'2',value:'上城区'},
{id:'3',value:'下城区'},
{id:'4',value:'江干区'},
{id:'5',value:'拱墅区'},
{id:'6',value:'西湖区'}
]}
],
transitionEnd:function(indexArr, data){
//console.log(data);
},
callback:function(indexArr, data){
console.log(data);
}
});
var mobileSelect5 = new MobileSelect({
trigger: '#trigger5',
title: '车型选择',
wheels: [
{data : UplinkData}
],
position: [2,0],
transitionEnd:function(indexArr, data){
//console.log(data);
},
callback:function(indexArr, data){
console.log(data);
}
});
</script>
</body>
</html>