Turn checkboxes and radio buttons in toggle switches.
fork from : https://github.com/Bttstrp/bootstrap-switch.git

Stein, Peter 9e89f8fe89 Update bootstrapSwitch.css 12 年之前
examples 6212f706fa Update index.html 12 年之前
static 9e89f8fe89 Update bootstrapSwitch.css 12 年之前
.gitignore 40c9d7eb1d welcome 12 年之前
LICENSE 40c9d7eb1d welcome 12 年之前
README.md cab173c13f Update README.md 12 年之前

README.md

Bootstrap-switch

You can now also use radio buttons as switches.

Demo

http://www.larentis.eu/switch/

Usage

Just include Twitter Bootstrap, jQuery, Bootstrap Switch CSS and Javascript

<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8;" />
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<link rel="stylesheet" href="bootstrapSwitch.css">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="bootstrapSwitch.js"></script>  // master
<script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/1.3/bootstrapSwitch.min.js">  // from cdnjs.com

Less

If you want to use your bootstrap vars edit bootstrapSwitch.less and then compile the less file

lessc static/less/bootstrapSwitch.less static/stylesheets/bootstrapSwitch.css

Basic Example

checkboxes:

<div class="switch">
    <input type="checkbox">
</div>

radioboxes:

<div class="switch">
    <input type="radio">
</div>

Large, small or mini

checkboxes:

<div class="switch switch-large">  <!-- switch-large, switch-small or switch-mini -->
    <input type="checkbox">
</div>

radioboxes:

<div class="switch switch-large">  <!-- switch-large, switch-small or switch-mini -->
    <input type="radio">
</div>

Colors

checkboxes:

<div class="switch" data-on="danger" data-off="warning">  <!-- primary, info, success, warning, danger and default -->
    <input type="checkbox">
</div>

radioboxes:

<div class="switch" data-on="danger" data-off="warning">  <!-- primary, info, success, warning, danger and default -->
    <input type="radio">
</div>

Animation

checkboxes:

<div class="switch" data-animated="false">
    <input type="checkbox">
</div>

radioboxes:

<div class="switch" data-animated="false">
    <input type="radio">
</div>

Text

checkboxes:

<div class="switch" data-on-label="SI" data-off-label="NO">
    <input type="checkbox">
</div>

radioboxes:

<div class="switch" data-on-label="SI" data-off-label="NO">
    <input type="radio">
</div>

HTML Text

checkboxes:

<div class="switch" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
    <input type="checkbox">
</div>

radioboxes:

<div class="switch" data-on-label="<i class='icon-ok icon-white'></i>" data-off-label="<i class='icon-remove'></i>">
    <input type="radio">
</div>

Initial values

checkboxes:

<div class="switch">
    <input type="checkbox" checked="checked" disabled="disabled">
</div>

radioboxes:

<div class="switch">
    <input type="radio" checked="checked" disabled="disabled">
</div>

Event handler

$('#mySwitch').on('switch-change', function (e, data) {
    var $el = $(data.el)
      , value = data.value;
    console.log(e, $el, value);
});

Methods

$('#mySwitch').bootstrapSwitch('toggleActivation');
$('#mySwitch').bootstrapSwitch('isActive');
$('#mySwitch').bootstrapSwitch('setActive', false);
$('#mySwitch').bootstrapSwitch('setActive', true);
$('#mySwitch').bootstrapSwitch('toggleState');
$('.mySwitch').bootstrapSwitch('toggleRadioState'); // the radiobuttons need a class not a ID
$('#mySwitch').bootstrapSwitch('setState', true);
$('#mySwitch').bootstrapSwitch('status');  // returns true or false
$('#mySwitch').bootstrapSwitch('destroy');

License

Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0