forked from slawomir-zaziablo/range-slider
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
252 lines (240 loc) · 8.9 KB
/
index.html
File metadata and controls
252 lines (240 loc) · 8.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Range Slider</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0 0 50px;
color: #333;
font-size: 14px;
}
p {
margin: 0;
}
pre {
padding: 20px 20px 0 0;
background: #f9f9f9;
border: 1px solid #f2f2f2;
margin-bottom: 30px;
line-height: 2em;
}
.top {
background-color: #333;
border-bottom: 3px solid #00b3bc;
color: #fff;
padding: 20px;
}
.top h1 {
font-size: 20px;
text-align: center;
}
.container {
width: 80%;
margin: 70px auto;
}
.slider-container {
width: 90%;
max-width: 500px;
margin: 0 auto 50px;
}
.config {
border: 1px solid #f2f2f2;
margin-bottom: 30px;
line-height: 1.7em;
}
.config table {
border-collapse: collapse;
width: 100%;
}
.config table td {
padding: 10px;
border-bottom: 1px solid #f2f2f2;
}
.config table tr:nth-child(even) td {
background-color: #f9f9f9;
}
.mb {
margin-bottom: 15px;
}
.label {
font-weight: bold;
white-space: nowrap;
}
.download {
margin-bottom: 20px;
}
.download a {
text-decoration: none;
color: #00969b;
font-size: 16px;
}
</style>
<link rel="stylesheet" href="css/rSlider.min.css">
</head>
<body>
<div class="top">
<h1>single/range slider - pure JS</h1>
</div>
<div class="container">
<div class="slider-container">
<input type="text" id="slider" class="slider" />
</div>
<div class="slider-container">
<input type="text" id="slider2" class="slider" />
</div>
<div class="slider-container">
<input type="text" id="slider3" class="slider" />
</div>
<div class="download">
<a href="https://github.com/slawomir-zaziablo/range-slider">Download from Github</a>
</div>
<div class="desc">
<p>A MIT licensed JS range slider plugin, no dependencies required.</p>
<h2>How to use</h2>
<p>Include css and js files:</p>
<pre>
<link rel="stylesheet" href="css/rSlider.min.css">
<script src="js/rSlider.min.js"></script>
</pre>
<p>Add an input field to your HTML code</p>
<pre>
<input type="text" id="sampleSlider" />
</pre>
<p>Add a small Javascript piece to your JS file:</p>
<pre>
var mySlider = new rSlider({
target: '#sampleSlider',
values: [2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015],
range: true,
tooltip: true,
scale: true,
labels: true,
set: [2010, 2013]
});
</pre>
<h2>Configuration</h2>
<div class="config">
<table>
<tr>
<td class="label">target</td>
<td>Single element's class/id or HTML object e.g. <strong>document.getElementById('sampleSlider')</strong></td>
</tr>
<tr>
<td class="label">values</td>
<td>A flat array of values e.g. <strong>[1, 2, , 4, 5]</strong> or object e.g. <strong>{min: 1, max: 10}</strong>.</td>
</tr>
<tr>
<td class="label">step</td>
<td>While using an object value {min: 0, max: 100} the step can be defined e.g. <strong>10</strong></td>
</tr>
<tr>
<td class="label">range</td>
<td>Boolean (true or false) to set if the slider is range or single type <strong>(default false)</strong></td>
</tr>
<tr>
<td class="label">set</td>
<td>A flat array of one (single slider) or two (range slider) values to set initial values <strong>(optional)</strong></td>
</tr>
<tr>
<td class="label">width</td>
<td>Number or string value (e.g. 400 or '400px') to set the slider width <strong>(optional)</strong>. Default the closest parent div width is used.</td>
</tr>
<tr>
<td class="label">scale</td>
<td>Boolean (true or false) to show or hide scale <strong>(default true)</strong>.</td>
</tr>
<tr>
<td class="label">labels</td>
<td>Boolean (true or false) to show or hide scale labels <strong>(default true)</strong>.</td>
</tr>
<tr>
<td class="label">tooltip</td>
<td>Boolean (true or false) to show or hide tooltips <strong>(default true)</strong>.</td>
</tr>
<tr>
<td class="label">disabled</td>
<td>Boolean (true or false) to disable/enable slider <strong>(default false)</strong>.</td>
</tr>
</table>
</div>
<h2>Methods</h2>
<p class="mb">Methods can be used after a new instance of slider is initiated e.g. <strong>slider.getValue();</strong></p>
<div class="config">
<table>
<tr class="row">
<td class="label">getValue()</td>
<td>Returns selected values.</td>
</tr>
<tr class="row">
<td class="label">disabled(true/false)</td>
<td>Makes a slider disabled/enabled</td>
</tr>
<tr class="row">
<td class="label">onChange(callback)</td>
<td>the callback function argument returns current selected values e.g<br><strong>mySlider.onChange(function (values) { // argument values represents current values });</strong></td>
</tr>
<tr class="row">
<td class="label">setValues(start, end)</td>
<td>Method gets one (range: false) or two (range: true) parameters and sets the values (see example above).</td>
</tr>
<tr class="row">
<td class="label">destroy()</td>
<td>Removes an instance of slider e.g. <strong>mySlider.destroy();</strong></td>
</tr>
</table>
</div>
</div>
<div class="download">
<a href="https://github.com/slawomir-zaziablo/range-slider">Download from Github</a>
</div>
</div>
<script src="js/rSlider.min.js"></script>
<script>
(function () {
'use strict';
var init = function () {
var slider2 = new rSlider({
target: '#slider2',
values: [0, 1, 2, 3, 4, 5, 6, '7', 8],
range: false,
set: [5],
tooltip: false,
onChange: function (vals) {
console.log(vals);
}
});
var slider3 = new rSlider({
target: '#slider3',
values: {min: 0, max: 100},
step: 10,
range: true,
set: [10, 40],
scale: true,
labels: false,
onChange: function (vals) {
console.log(vals);
}
});
var slider = new rSlider({
target: '#slider',
values: [2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015],
range: true,
set: [2010, 2013],
onChange: function (vals) {
console.log(vals);
}
});
};
window.onload = init;
})();
</script>
</body>
</html>