JSFiddle - React, Tailwind, and code Playground

by Bacher

HTML

<div class="checkbox">
</div>

CSS

body { padding: 6px; }

.checkbox {
    position: relative;
    width: 46px;
    height: 46px;
}

.checkbox:before,
.checkbox.active-state:after {
    display: block;
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
}

.checkbox:before {    
    background: url("http://savepic.ru/4263978.png");
    z-index: -1;
}

.checkbox.active-state:after {
    border-radius: 12px;
    opacity: 0.6;
    background-image: -webkit-linear-gradient(top, #333 0%, #000 50%, #555 100%);
}

.checkbox.checked {
    background: url("http://savepic.ru/4323204.png");
}

JavaScript

$(".checkbox").on("mousedown", $("body"), function() {
    $(this).addClass("active-state");
});

$("body").on("mouseup", function() {
    $("*").removeClass("active-state");   
});
    
$(".checkbox").on("click", function() {
    $(this).toggleClass("checked");
});