-
Notifications
You must be signed in to change notification settings - Fork 102
/
index.html
239 lines (187 loc) · 5.87 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
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
<!DOCTYPE html>
<html>
<head>
<title>jQuery UI Switch Button Demo - Olivier Lance</title>
<link rel="stylesheet" href="jquery.switchButton.css">
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="wrapper">
<a href="https://github.com/olance/jQuery-switchButton"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
<h1>jQuery UI iPhone-like Switch Button Demo</h1>
<p>
This widget will replace the receiver element with an iPhone-style switch
button with two states: "on" and "off". Labels of the states are customizable,
as are their presence and position. The receiver element's "checked" attribute
is updated according to the state of the switch, so that it can be used in
a <code><form></code>, on a checkbox input for instance.
</p>
<p>
This widget has been made to answer my specific needs, so there's room for
improvement here and there, but it does the job for me as it is.
</p>
<h2>Basic usage</h2>
<p>
Using the following markup:
</p>
<pre>
<input type="checkbox" value="1" checked></pre>
<p>
You can simply call <code>switchButton()</code> without any
options on the checkbox element, and you'll get that:
</p>
<div class="demo" id="basic">
<input type="checkbox" value="1" checked>
</div>
<p>
The widget's elements are floated, so you must wrap the checkbox in its own
<code><div></code> if you want to inline it with some
text:
</p>
<pre>
It is
<div class="switch-wrapper">
<input type="checkbox" value="1" checked>
</div>
!</pre>
<p>
Apply some styles to the wrapping <code><div></code> and
everything will look perfect:
</p>
<pre>
.switch-wrapper {
display: inline-block;
position: relative;
top: 3px;
}</pre>
<div class="demo" id="basic2">
It is
<div class="switch-wrapper">
<input type="checkbox" value="1" checked>
</div>
!
</div>
<h2>Playing with options</h2>
<h3>Labels texts</h3>
<p>
The first thing you might want to do, is changing the labels texts. The
<code>on_label</code> and <code>off_label</code>
options allow you to do that:
</p>
<pre>
$("input[type=checkbox]").switchButton({
on_label: 'yes',
off_label: 'no'
});</pre>
<div class="demo" id="labels">
I want to break free:
<div class="switch-wrapper">
<input type="checkbox" value="1" checked>
</div>
</div>
<h3>Default state</h3>
<p>
The widget will use the <code>checked</code> attribute of the
receiver to determine the initial state of the switch.<br>
However, you can force it to be on or off by specifying it in the options:
</p>
<pre>
// Force the checked property to false, whatever state it is in initially
$("input[type=checkbox]").switchButton({
checked: false
});</pre>
<div class="demo" id="default">
<input type="checkbox" value="1" checked>
</div>
<h3>Other labels options</h3>
<p>
Maybe you'd like to display the button without any label at all:
</p>
<pre>
$("input[type=checkbox]").switchButton({
show_labels: false
});</pre>
<div class="demo" id="labels2-1">
<input type="checkbox" value="1" checked>
</div>
<p>
Or display them on one side only:
</p>
<pre>
$("input[type=checkbox]").switchButton({
labels_placement: "right"
});</pre>
<div class="demo" id="labels2-2">
<input type="checkbox" value="1" checked>
</div>
<pre>
$("input[type=checkbox]").switchButton({
labels_placement: "left"
});</pre>
<div class="demo" id="labels2-3">
<input type="checkbox" value="1" checked>
</div>
<h3>Slider options</h3>
<p>
You can customize the size of the slider and the sliding element:
</p>
<pre>
$("input[type=checkbox]").switchButton({
width: 100,
height: 40,
button_width: 50
});</pre>
<div class="slider demo" id="slider-1">
<input type="checkbox" value="1" checked>
</div>
<pre>
$("input[type=checkbox]").switchButton({
width: 100,
height: 40,
button_width: 70
});</pre>
<div class="slider demo" id="slider-2">
<input type="checkbox" value="1">
</div>
<p>
Note that the <code>font-size</code> of the labels for both
examples above have been changed in the CSS.
</p>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script src="jquery.switchButton.js"></script>
<script>
$(function() {
$('#basic.demo input').switchButton();
$('#basic2.demo input').switchButton();
$("#labels.demo input").switchButton({
on_label: 'YES',
off_label: 'NO'
});
$("#default.demo input").switchButton({
checked: false
});
$("#labels2-1.demo input").switchButton({
show_labels: false
});
$("#labels2-2.demo input").switchButton({
labels_placement: "right"
});
$("#labels2-3.demo input").switchButton({
labels_placement: "left"
});
$("#slider-1.demo input").switchButton({
width: 100,
height: 40,
button_width: 50
});
$("#slider-2.demo input").switchButton({
width: 100,
height: 40,
button_width: 70
});
})
</script>
</body>
</html>