提交 | 用户 | 时间
|
58d006
|
1 |
Bootstrap-switch v.1.8 |
A |
2 |
======================== |
|
3 |
|
|
4 |
You can now also use radio buttons and checkboxes as switches. |
|
5 |
|
|
6 |
|
|
7 |
Demo |
|
8 |
---- |
|
9 |
Hurray! http://www.larentis.eu/switch/ moves to github pages and we are happy to tell you that we have bought a new domain: http://www.bootstrap-switch.org . Some troubles can occur so please, don't hate us :') |
|
10 |
|
|
11 |
|
|
12 |
Usage |
|
13 |
----- |
|
14 |
Just include Twitter Bootstrap, jQuery, Bootstrap Switch CSS and Javascript |
|
15 |
``` html |
|
16 |
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" /> |
|
17 |
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css"> |
|
18 |
<link rel="stylesheet" href="bootstrap-switch.css"> |
|
19 |
|
|
20 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> |
|
21 |
<script src="bootstrap-switch.js"></script> // master |
|
22 |
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/1.7/bootstrap-switch.min.js"> // from cdnjs.com |
|
23 |
``` |
|
24 |
|
|
25 |
Less |
|
26 |
---- |
|
27 |
If you want to use your bootstrap vars edit bootstrapSwitch.less and then compile the less file |
|
28 |
``` bash |
|
29 |
lessc static/less/bootstrap-switch.less static/stylesheets/bootstrap-switch.css |
|
30 |
``` |
|
31 |
|
|
32 |
Supported browsers |
|
33 |
------------------ |
|
34 |
I'm not going to support ancient browsers! (it works on IE8+) |
|
35 |
|
|
36 |
Basic Example |
|
37 |
------------- |
|
38 |
checkboxes: |
|
39 |
|
|
40 |
``` html |
|
41 |
<div class="make-switch"> |
|
42 |
<input type="checkbox"> |
|
43 |
</div> |
|
44 |
``` |
|
45 |
|
|
46 |
radioboxes: |
|
47 |
|
|
48 |
``` html |
|
49 |
<div class="make-switch"> |
|
50 |
<input type="radio"> |
|
51 |
</div> |
|
52 |
``` |
|
53 |
|
|
54 |
|
|
55 |
Large, small or mini |
|
56 |
-------------------- |
|
57 |
checkboxes: |
|
58 |
|
|
59 |
``` html |
|
60 |
<div class="make-switch switch-large"> <!-- switch-large, switch-small or switch-mini --> |
|
61 |
<input type="checkbox"> |
|
62 |
</div> |
|
63 |
``` |
|
64 |
|
|
65 |
radioboxes: |
|
66 |
|
|
67 |
``` html |
|
68 |
<div class="make-switch switch-large"> <!-- switch-large, switch-small or switch-mini --> |
|
69 |
<input type="radio"> |
|
70 |
</div> |
|
71 |
``` |
|
72 |
|
|
73 |
|
|
74 |
Colors |
|
75 |
------ |
|
76 |
checkboxes: |
|
77 |
|
|
78 |
``` html |
|
79 |
<div class="make-switch" data-on="danger" data-off="warning"> <!-- primary, info, success, warning, danger and default --> |
|
80 |
<input type="checkbox"> |
|
81 |
</div> |
|
82 |
``` |
|
83 |
|
|
84 |
radioboxes: |
|
85 |
|
|
86 |
``` html |
|
87 |
<div class="make-switch" data-on="danger" data-off="warning"> <!-- primary, info, success, warning, danger and default --> |
|
88 |
<input type="radio"> |
|
89 |
</div> |
|
90 |
``` |
|
91 |
|
|
92 |
|
|
93 |
Animation |
|
94 |
--------- |
|
95 |
checkboxes: |
|
96 |
|
|
97 |
``` html |
|
98 |
<div class="make-switch" data-animated="false"> |
|
99 |
<input type="checkbox"> |
|
100 |
</div> |
|
101 |
``` |
|
102 |
|
|
103 |
radioboxes: |
|
104 |
|
|
105 |
``` html |
|
106 |
<div class="make-switch" data-animated="false"> |
|
107 |
<input type="radio"> |
|
108 |
</div> |
|
109 |
``` |
|
110 |
|
|
111 |
|
|
112 |
Text |
|
113 |
----- |
|
114 |
checkboxes: |
|
115 |
|
|
116 |
``` html |
|
117 |
<div class="make-switch" data-on-label="SI" data-off-label="NO"> |
|
118 |
<input type="checkbox"> |
|
119 |
</div> |
|
120 |
``` |
|
121 |
|
|
122 |
radioboxes: |
|
123 |
|
|
124 |
``` html |
|
125 |
<div class="make-switch" data-on-label="SI" data-off-label="NO"> |
|
126 |
<input type="radio"> |
|
127 |
</div> |
|
128 |
``` |
|
129 |
|
|
130 |
|
|
131 |
Text Label |
|
132 |
---------- |
|
133 |
checkboxes: |
|
134 |
|
|
135 |
``` html |
|
136 |
<div class="make-switch" data-text-label="My Slider Text"> |
|
137 |
<input type="checkbox"> |
|
138 |
</div> |
|
139 |
``` |
|
140 |
|
|
141 |
radioboxes: |
|
142 |
|
|
143 |
``` html |
|
144 |
<div class="make-switch" data-text-label="My Slider Text"> |
|
145 |
<input type="radio"> |
|
146 |
</div> |
|
147 |
``` |
|
148 |
|
|
149 |
|
|
150 |
HTML Text |
|
151 |
---------- |
|
152 |
checkboxes: |
|
153 |
|
|
154 |
``` html |
|
155 |
<div class="make-switch" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>"> |
|
156 |
<input type="checkbox"> |
|
157 |
</div> |
|
158 |
``` |
|
159 |
|
|
160 |
radioboxes: |
|
161 |
|
|
162 |
``` html |
|
163 |
<div class="make-switch" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>"> |
|
164 |
<input type="radio"> |
|
165 |
</div> |
|
166 |
``` |
|
167 |
|
|
168 |
|
|
169 |
Initial values |
|
170 |
-------------- |
|
171 |
checkboxes: |
|
172 |
|
|
173 |
``` html |
|
174 |
<div class="make-switch"> |
|
175 |
<input type="checkbox" checked="checked" disabled="disabled"> |
|
176 |
</div> |
|
177 |
``` |
|
178 |
radioboxes: |
|
179 |
|
|
180 |
|
|
181 |
``` html |
|
182 |
<div class="make-switch"> |
|
183 |
<input type="radio" checked="checked" disabled="disabled"> |
|
184 |
</div> |
|
185 |
``` |
|
186 |
|
|
187 |
|
|
188 |
Event handler |
|
189 |
------------- |
|
190 |
``` javascript |
|
191 |
$('#mySwitch').on('switch-change', function (e, data) { |
|
192 |
var $el = $(data.el) |
|
193 |
, value = data.value; |
|
194 |
console.log(e, $el, value); |
|
195 |
}); |
|
196 |
``` |
|
197 |
|
|
198 |
Methods |
|
199 |
------- |
|
200 |
``` javascript |
|
201 |
$('#mySwitch').bootstrapSwitch('toggleActivation'); |
|
202 |
$('#mySwitch').bootstrapSwitch('isActive'); |
|
203 |
$('#mySwitch').bootstrapSwitch('setActive', false); |
|
204 |
$('#mySwitch').bootstrapSwitch('setActive', true); |
|
205 |
$('#mySwitch').bootstrapSwitch('toggleState'); |
|
206 |
$('.mySwitch').bootstrapSwitch('toggleRadioState'); // the radiobuttons need a class not a ID, don't allow uncheck radio switch |
|
207 |
$('.mySwitch').bootstrapSwitch('toggleRadioStateAllowUncheck'); // don't allow uncheck radio switch |
|
208 |
$('.mySwitch').bootstrapSwitch('toggleRadioStateAllowUncheck', false); // don't allow uncheck radio switch |
|
209 |
$('.mySwitch').bootstrapSwitch('toggleRadioStateAllowUncheck', true); // allow uncheck radio switch |
|
210 |
$('#mySwitch').bootstrapSwitch('setState', true); |
|
211 |
$('#mySwitch').bootstrapSwitch('setState', true || false, true); // sets the state without getting the switch-change event |
|
212 |
$('#mySwitch').bootstrapSwitch('setOnLabel', onValue); // sets the text of the "on" label |
|
213 |
$('#mySwitch').bootstrapSwitch('setOffLabel', offValue); // sets the text of the "off" label |
|
214 |
$('#mySwitch').bootstrapSwitch('setOnClass', onClass); // sets the left color class |
|
215 |
$('#mySwitch').bootstrapSwitch('setOffClass', offClass); // sets the right color class |
|
216 |
$('#mySwitch').bootstrapSwitch('setAnimated', animated); // sets true or false for animation |
|
217 |
$('#mySwitch').bootstrapSwitch('setSizeClass', size); // sets 'switch-mini', 'switch-small' or 'switch-large' |
|
218 |
$('#mySwitch').bootstrapSwitch('status'); // returns true or false |
|
219 |
$('#mySwitch').bootstrapSwitch('destroy'); |
|
220 |
``` |
|
221 |
|
|
222 |
License |
|
223 |
------- |
|
224 |
Licensed under the Apache License, Version 2.0 |
|
225 |
http://www.apache.org/licenses/LICENSE-2.0 |