This time I will share jQuery Plugin and tutorial about Basic ON/OFF Toggle Switches In jQuery – Switcher, hope it will help you in programming stack.
Switcher is an ultra-light jQuery plugin that transforms the native Checkbox and Radio Button elements into iOS inspired on/off toggle switches just with a JS call.
Click on the switches to toggle between ON and OFF states with a smooth transition effect based on CSS3.
How to use it:
1. Load the stylesheet switcher.css
in the head
, and the JavaScript file switcher.js
after jQuery library.
1 |
< link href = "css/switcher.css" rel = "stylesheet" > |
3 |
integrity = "sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" |
4 |
crossorigin = "anonymous" > |
6 |
< script src = "js/jquery.switcher.js" ></ script > |
2. Initialize the plugin to apply the plugin to all the checkboxes and radio buttons in the document.
02 |
< div class = "form-check form-check-inline" > |
03 |
< input class = "form-check-input" type = "checkbox" id = "inlineCheckbox1" value = "option1" > |
05 |
< div class = "form-check form-check-inline" > |
06 |
< input class = "form-check-input" type = "checkbox" id = "inlineCheckbox2" value = "option2" > |
08 |
< div class = "form-check form-check-inline" > |
09 |
< input class = "form-check-input" type = "checkbox" id = "inlineCheckbox3" value = "option3" disabled> |
12 |
< h2 >Radio Buttons</ h2 > |
13 |
< div class = "form-check form-check-inline" > |
14 |
< input class = "form-check-input" type = "radio" name = "inlineRadioOptions" id = "inlineRadio1" value = "option1" > |
16 |
< div class = "form-check form-check-inline" > |
17 |
< input class = "form-check-input" type = "radio" name = "inlineRadioOptions" id = "inlineRadio2" value = "option2" > |
19 |
< div class = "form-check form-check-inline" > |
20 |
< input class = "form-check-input" type = "radio" name = "inlineRadioOptions" id = "inlineRadio3" value = "option3" disabled> |
3. You can also initialize the plugin on specific checboxes or radio buttons.
1 |
$.switcher( 'input[type=checkbox]' ); |
3 |
$.switcher( 'input[type=radio]' ); |
4. Override the default CSS to create your own styles.
02 |
background-color : #bdc1c2 ; |
03 |
display : inline- block ; |
07 |
box-sizing: border-box; |
08 |
vertical-align : middle ; |
11 |
transition: border-color 0.25 s; |
13 |
box-shadow: inset 1px 1px 1px rgba( 0 , 0 , 0 , 0.15 ); |
17 |
font-family : sans-serif ; |
22 |
display : inline- block ; |
31 |
background-color : #ffffff ; |