پیشنمایش زنده
کد HTML
<label class="morphing-checkbox">
<input type="checkbox" />
<div class="checkbox-body">
<div class="cube">
<div class="front"></div>
<div class="back"></div>
<div class="top"></div>
<div class="bottom"></div>
<div class="left"></div>
<div class="right"></div>
</div>
<svg viewBox="0 0 24 24" class="checkmark">
<path d="M4,12 L9,17 L20,6"></path>
</svg>
<div class="ripple"></div>
</div>
</label>
کد CSS
.morphing-checkbox {
--checkbox-size: 2.5em;
--checkbox-color: #6366f1;
--checkbox-color-hover: #4f46e5;
--checkbox-shadow: rgba(99, 102, 241, 0.3);
--checkmark-color: white;
--cubic-bezier: cubic-bezier(0.16, 1, 0.3, 1);
position: relative;
display: inline-block;
cursor: pointer;
user-select: none;
}
.morphing-checkbox input {
position: absolute;
opacity: 0;
width: 0;
height: 0;
}
.checkbox-body {
position: relative;
width: var(--checkbox-size);
height: var(--checkbox-size);
perspective: 25em;
}
.cube {
position: absolute;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.6s var(--cubic-bezier);
}
.cube div {
position: absolute;
width: 100%;
height: 100%;
background-color: var(--checkbox-color);
backface-visibility: hidden;
border-radius: 0.3em;
box-shadow: 0 0.2em 0.6em var(--checkbox-shadow);
transform-style: preserve-3d;
}
.cube .front {
transform: translateZ(calc(var(--checkbox-size) / 2));
}
.cube .back {
transform: rotateY(180deg) translateZ(calc(var(--checkbox-size) / 2));
}
.cube .top {
transform: rotateX(90deg) translateZ(calc(var(--checkbox-size) / 2));
}
.cube .bottom {
transform: rotateX(-90deg) translateZ(calc(var(--checkbox-size) / 2));
}
.cube .left {
transform: rotateY(-90deg) translateZ(calc(var(--checkbox-size) / 2));
}
.cube .right {
transform: rotateY(90deg) translateZ(calc(var(--checkbox-size) / 2));
}
.morphing-checkbox:hover .cube div {
background-color: var(--checkbox-color-hover);
}
.morphing-checkbox input:checked + .checkbox-body .cube {
transform: rotateY(180deg) rotateZ(180deg);
}
.checkmark {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
width: 60%;
height: 60%;
fill: none;
stroke: var(--checkmark-color);
stroke-width: 3;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 24;
stroke-dashoffset: 24;
z-index: 2;
pointer-events: none;
}
.morphing-checkbox input:checked + .checkbox-body .checkmark {
animation: check-animation 0.5s var(--cubic-bezier) forwards 0.3s;
}
@keyframes check-animation {
0% {
transform: translate(-50%, -50%) scale(0);
stroke-dashoffset: 24;
}
50% {
transform: translate(-50%, -50%) scale(1.2);
}
100% {
transform: translate(-50%, -50%) scale(1);
stroke-dashoffset: 0;
}
}
.ripple {
position: absolute;
top: 50%;
left: 50%;
width: 0;
height: 0;
transform: translate(-50%, -50%);
border-radius: 50%;
background-color: rgba(255, 255, 255, 0.5);
opacity: 0;
z-index: 1;
pointer-events: none;
}
.morphing-checkbox input:checked + .checkbox-body .ripple {
animation: ripple 0.6s var(--cubic-bezier);
}
@keyframes ripple {
0% {
width: 0;
height: 0;
opacity: 0.5;
}
100% {
width: 200%;
height: 200%;
opacity: 0;
}
}
.morphing-checkbox input:focus + .checkbox-body::after {
content: "";
position: absolute;
top: -0.3em;
left: -0.3em;
right: -0.3em;
bottom: -0.3em;
border-radius: 0.6em;
border: 0.15em solid rgba(99, 102, 241, 0.4);
pointer-events: none;
opacity: 0;
animation: focus-animation 0.3s var(--cubic-bezier) forwards;
}
@keyframes focus-animation {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.morphing-checkbox:active .cube {
transform: scale(0.9);
}
.morphing-checkbox input:checked:active + .checkbox-body .cube {
transform: scale(0.9) rotateY(180deg) rotateZ(180deg);
}