JSFiddle - React, Tailwind, and code Playground
HTML
<input type="checkbox" class="ios" />
CSS
/* Alternative Theme */
/* ---------------- */
.ios-ui-select{
border-color: #d1d1d1;
width: 28px;
height: 28px;
-webkit-border-radius: 100%;
border-radius: 100%;
opacity: 1;
-webkit-box-shadow: inset 0 0 0 2px #d6e0e6;
box-shadow: inset 0 0 0 2px #d6e0e6;
width: 22px;
z-index: 2;
text-align: center;
display: inline-block;
cursor: pointer;
height: 22px;
-webkit-border-radius: 18px;
border-radius: 18px;
-webkit-transition: all 350ms cubic-bezier(0, 0.89, 0.44, 1);
-moz-transition: all 350ms cubic-bezier(0, 0.89, 0.44, 1);
-o-transition: all 350ms cubic-bezier(0, 0.89, 0.44, 1);
transition: all 350ms cubic-bezier(0, 0.89, 0.44, 1);
text-indent: -9999px;
display: inline-block;
}
.ios-ui-select.checked {
-webkit-box-shadow: inset 0 0 0 14px #4ad337;
box-shadow: inset 0 0 0 14px #4ad337;
opacity: 1 !important;
}
.ios-ui-select.checked .inner{
-moz-transform: scale(1);
-webkit-transform: scale(1);
-o-transform: scale(1);
-ms-transform: scale(1);
transform: scale(1);
}
.ios-ui-select .inner{
background:...
JavaScript
/**
* iosCheckbox.js
* Version: 1.0.0
* Author: Ron Masas
*/
(function($) {
$.fn.extend({
iosCheckbox: function() {
this.destroy = function(){
$(this).each(function() {
$(this).next('.ios-ui-select').remove();
});
};
if ($(this).attr('data-ios-checkbox') === 'true') {
return;
}
$(this).attr('data-ios-checkbox', 'true');
$(this).each(function(i) {
/**
* Original checkbox element
*/
var org_checkbox = $(this);
org_checkbox.addClass('ios-checkbox-input');
/**
* Wrap the input field with a div containing ID and classes
* The ID of wrapper element is based on ID, Name or Index of input field
*/
var org_checkbox_id = 'ios-checkbox-' + ( org_checkbox.attr('name') || org_checkbox.attr('id') || (i + 1) ),
org_checkbox_classes = 'ios-checkbox-wrap';
org_checkbox.wrap('<div id="' + org_checkbox_id + '" class="' + org_checkbox_classes + '"></div>');
/**
* iOS checkbox div
*/
var ios_checkbox = jQuery("<div>", {
class: 'ios-ui-select'
}).append(jQuery("<div>", {
class: 'inner'
}));
// If the original checkbox is checked, add checked class to the ios checkbox.
if (org_checkbox.is(":checked")) {
ios_checkbox.addClass("checked");
}
// Hide the original checkbox and print the new one.
org_checkbox.hide().after(ios_checkbox);
if (org_checkbox.is(":disabled")){
// In case the original checkbox...