Only thing you need is to add a checked attribute to your checkbox input. Simple as that.
<input type="checkbox" class="js-switch" checked />
Result:
You can add as many switches as you like, as long as their corresponding checkboxes have the same class. Select them and make new instance of the Switchery class for every of them.
var elems = Array.prototype.slice.call(document.querySelectorAll('.js-switch'));
elems.forEach(function(html) {var switchery = new Switchery(html);});
Result:
Use the disabled option to make your switch active or inactive.
var switchery = new Switchery(elem, { disabled: true });
Result:
Customize the default opacity of the disabled switch like so:
var switchery = new Switchery(elem, { disabled: true, disabledOpacity: 0.75 });
Result:
You can change the primary of the switch to fit your design perfectly:
var switchery = new Switchery(elem, { color: '#41b7f1' });
Result:
Or the secondary color, which will change the switch shadow and default border:
var switchery = new Switchery(elem, { color: '#fec200', secondaryColor: '#fec200' });
Result:
If you are an adventurer and like to use legacy browsers, like IE8 and IE7, apply your favourite fix for rounded corners and box shadows and try a slightly different approach.
var elems = document.querySelectorAll('.js-switch');
for (var i = 0; i < elems.length; i++) {var switchery = new Switchery(elems[i]);}
适用浏览器:360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗. 不支持IE8及以下浏览器。
来源:站长素材