-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
172 lines (144 loc) · 4.46 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
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<title>input range</title>
<style>
body {
padding: 10%;
margin: 0;
}
.input-range {
position: relative;
height: 4px;
margin: 52px 0 8px;
background-color: #f5f5f5;
}
.input-range .pointer {
position: absolute;
top: 0;
left: 0;
margin: -5px 0 0 -7px;
width: 14px;
height: 14px;
background-color: #2f75bb;
border-radius: 50%;
cursor: col-resize;
opacity: 0.5;
}
.input-range .pointer.activate {
z-index: 1;
background-color: #2fbb64;
}
.input-range .pointer--high {
left: 100%;
}
.input-range .track {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 4px;
background-color: #2f75bb;
}
.input-range .track.activate {
background-color: #2fbb64;
}
.input-range .label {
position: absolute;
top: -50px;
left: 50%;
-webkit-transform: translate3d(-50%, 0, 0);
transform: translate3d(-50%, 0, 0);
min-width: 28px;
height: 16px;
padding: 10px 8px;
font-size: 16px;
background-color: #f5f5f5;
border: solid #d7d7d7 1px;
border-radius: 18px;
text-align: center;
}
.input-range .label.activate {
color: #fff;
background-color: #2fbb64;
border-color: #2fbb64;
}
.input-range .label--low {
left: 0;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.input-range .label--high {
left: 100%;
-webkit-transform: translate3d(-100%, 0, 0);
transform: translate3d(-100%, 0, 0);
}
</style>
</head>
<body>
<div class="input-range" data-role="range" data-step="5">
<div class="track" data-track></div>
<div class="pointer" data-pointer></div>
<div class="label" data-label></div>
</div>
<div style="height: 100px;"></div>
<div class="input-range" data-role="range" data-min="-11.5" data-max="3" data-step="2.6" data-value="-2" data-name="testing1">
<input type="hidden" data-input>
<div class="track" data-track></div>
<div class="pointer" data-pointer></div>
<div class="label" data-label></div>
</div>
<div style="height: 100px;"></div>
<div class="input-range" data-role="range" data-min="-13" data-max="2" data-step="2" data-value="-9, -3" data-name="testing2">
<input type="hidden" data-input>
<div class="track" data-track></div>
<div class="pointer pointer--low" data-pointer-low></div>
<div class="pointer pointer--high" data-pointer-high></div>
<div class="label label--low" data-label-low></div>
<div class="label label--high" data-label-high></div>
</div>
<button class="getValue">getValue</button>
<button class="setTrack">setTrack</button>
<div style="height: 100px;"></div>
<script src="https://cdn.bootcss.com/zepto/1.2.0/zepto.min.js"></script>
<script src="MRange.min.js"></script>
<script>
$(function() {
'use strict';
// 事件监听示例
window.ahm.range.testing1.on('dragstart', function(e) {
console.log('dragstart, value:', e._args.value);
});
window.ahm.range.testing1.on('dragmove', function(e) {
console.log('dragmove, value:', e._args.value);
});
window.ahm.range.testing1.on('dragend', function(e) {
console.log('dragend, value:', e._args.value);
});
// 事件移除示例
window.ahm.range.testing2.on('dragmove', function(e) {
console.log('dragmove, value:', e._args.value);
if (e._args.value === '-13,2') {
window.ahm.range.testing2.off('dragmove');
}
});
$('.getValue').on('click', function() {
var value = window.ahm.range.testing2.getValue();
alert(value);
});
$('.setTrack').on('click', function() {
// 可选项,如不设置默认为DOM结构上设置的`data`属性值
var option = {
min: 5,
max: 50,
step: 3,
value: '12, 30'
}
window.ahm.range.testing2.setTrack(option);
});
});
</script>
</body>
</html>