UI Switch (boolean slider)
A little UI Switch that uses true/false classes to determine states. Utilizes CSS3 and jQuery to function
HTML
<div class="bool-slider true disabled">
<div class="inset">
<div class="control"></div>
</div>
</div>
CSS
.bool-slider
{
border: 1px solid #CCC;
color: #FFF;
font-size: 18px;
font-weight: 800;
font-family: Helvetica, Verdana, Arial, sans-serif;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
height: 35px;
width: 100px;
border-radius: 25px;
border-width: 4px;
}
.bool-slider.true .inset
{
background-color: #51a351;
*background-color: #499249;
background-image: linear-gradient(top, #62c462, #51a351);
background-repeat: repeat-x;
border-color: #51a351 #51a351 #387038;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
background-image: none;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.bool-slider.true .inset .control{float: left}
.bool-slider.true .inset .control:after
{
content: 'On';
position: relative;
right: -135%;
top: 20%;
}
.bool-slider.false .inset
{
background-color: #da4f49;
*background-color: #bd362f;
background-image: linear-gradient(top, #ee5f5b, #bd362f);
background-repeat: repeat-x;
border-color: #bd362f #bd362f #802420;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
background-image: none;
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
}
.bool-slider.false .inset .control{float: right}
.bool-slider.false .inset .control:before
{
content: 'Off';
position: relative;
left: -100%;
top: 20%;
}
.bool-slider .inset
{
width: 100%;
height: 100%;
border-radius: 20px;
}
.bool-slider .inset .control
{
background-color: #000;
width: 40%;
height: 100%;
border-radius: 20px;
background-color: #f5f5f5;
*background-color: #e6e6e6;
background-image: linear-gradient(top, #ffffff, #e6e6e6);
background-repeat: repeat-x;
border-width:4px;
border-color:black
}
.bool-slider .inset .control:hover
{
cursor:...
JavaScript
$(document).ready(function() {
$('.bool-slider .inset .control').click(function() {
if (!$(this).parent().parent().hasClass('disabled')) {
if ($(this).parent().parent().hasClass('true')) {
$(this).parent().parent().addClass('false').removeClass('true');
} else {
$(this).parent().parent().addClass('true').removeClass('false');
}
}
});
});