<body class="light">
<div class="switch">
<input type="checkbox" id="checkbox" class="checkbox hoverable">
<img id="img" src="https://dummyimage.com/600x400/0f3/fff">
</div>
</body>
.light {
background-color: #ececec;
}
.dark {
background-color: #000;
}
/*Стили для переключателя*/
.switch {
display: box;
display: flexbox;
display: flex;
box-align: center;
flex-align: center;
align-items: center;
}
.switch input[type="checkbox"] {
position: relative;
width: 70px;
height: 35px;
appearance: none;
outline: none;
background-color: #fff;
border-radius: 20px;
transition: .5s;
transition: .5s;
box-shadow: 2px 0 14px rgba(0, 0, 0, 0.2);
box-shadow: 2px 0 14px rgba(0, 0, 0, 0.2);
}
.switch input[type="checkbox"]:checked {
background-color: #101012;
}
.switch input[type="checkbox"]::before {
content: '';
position: absolute;
width: 35px;
height: 35px;
border-radius: 20px;
top: 0;
left: 2px;
background-color: #101012;
transition: .5s;
transition: .5s;
transform: scale(0.8);
transform: scale(0.8);
}
.switch input:checked[type="checkbox"]:before {
left: 35px;
background-color: #fff;
}
$(document).ready(function(swapImages){
$(".checkbox").click(function(){
$(".light").toggleClass("dark");
swapImages();
});
});
const images = [
{
selector: '#img',
dark: 'https://dummyimage.com/600x400/fc0/fff',
light: 'https://dummyimage.com/600x400/0f3/fff'
},
function swapImages() {
const isDark = $('.light').hasClass('dark');
for (let image of images) {
$(image.selector).attr('src', isDark ? image.dark : image.light);
}
}
];
This Pen doesn't use any external CSS resources.