"Button Switch V2"
Bootstrap 4.1.1 Snippet by opensourcematters

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div class="form-group row" data-key="disabled"> <label class="col-sm-4 control-label" for="input-model">Disabled</label> <div class="col-sm-8 input"> <div class="toggle"> <input type="checkbox" class="toggle-checkbox" id="disabled"> <label class="toggle-label" for="disabled"> <span class="toggle-inner"></span> <span class="toggle-switch"></span> </label> </div> </div> </div> </div> </div>
.toggle { position: relative; width: 65px; -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none; } .toggle-checkbox { display: none; } .toggle-label { display: block; overflow: hidden; cursor: pointer; border: 2px solid #FFF; border-radius: 30px; } .toggle-inner { display: block; width: 200%; margin-left: -100%; transition: margin 0.3s ease-in 0s; } .toggle-inner:before, .toggle-inner:after { display: block; float: left; width: 50%; height: 20px; padding: 0; line-height: 20px; font-size: 12px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold; box-sizing: border-box; } .toggle-inner:before { content: "ON"; padding-left: 14px; background-color: #007BFF; } .toggle-inner:after { content: "OFF"; padding-right: 14px; background-color: #999999; color: #333333; text-align: right; } /*Bolita*/ .toggle-switch { display: block; width: 18px; margin: 4px; background: #FFFFFF; position: absolute; top: 0; bottom: 0; right: 39px; border: 2px solid #FFFFFF; border-radius: 30px; transition: all 0.3s ease-in 0s; } .toggle-checkbox:checked + .toggle-label .toggle-inner { margin-left: 0; } .toggle-checkbox:checked + .toggle-label .toggle-switch { right: 0px; }
$(document).ready(function() { $(".toggle-checkbox").change(function() { if(this.checked) { alert("test"); } }); });

Related: See More


Questions / Comments: