switch
switch
by Mortsith777
HTML
<div class="center">
<input type="checkbox" value="1">
<input type="checkbox" value="2">
</div>
CSS
body {
margin: 0;
padding: 0;
background: #f3f3f3;
}
.center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
input[type="checkbox"] {
width: 200px;
height: 100px;
-webkit-appearance: none;
-moz-appearance: none;
background: #c6c6c6;
outline: none;
border-radius: 50px;
box-shadow: inset 0 0 5px rgba(0,0,0, .2);
transition: 0.5s;
position: relative;
}
input:checked[type="checkbox"] {
background: #02a9f4;
}
input[type="checkbox"]::before {
content: '';
position: absolute;
width: 100px;
height: 100px;
border-radius: 50%;
top: 0;
left: 0;
background: #fff;
transform: scale(1.1);
box-shadow: 0 2px 5px rgba(0,0,0, .2);
transition: 0.5s;
}
input:checked[type="checkbox"]::before {
left: 100px;
}
JavaScript
let ff;
ff = document.querySelectorAll("input")[0];
ff.onclick = function() {
if ((ff.checked == true) && (ff.value == "1")) {
document.body.style.backgroundColor = "#00ff00";
} else if ((ff.checked == true) && (ff.value == "2")) {
document.body.style.backgroundColor = "#ccff00";
}
else {
document.body.style.backgroundColor = "#03f3f3";
}
};