<div class="toggle-container" data-toggle>
<div class="toggle-egg">
</div>
</div>
body {
background: #27A5A4;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
}
.toggle-container {
width: 200px;
height: 100px;
background: #272727;
border-radius: 50px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
&[data-active="true"] {
.toggle-egg {
transform: rotateY(180deg);
left: 55%;
&:before {
opacity: 0.5;
}
&:after {
opacity: 0;
}
}
}
}
.toggle-egg {
width: 80px;
height: 80px;
background: #EDE4DF;
border-radius: 50%;
position: absolute;
left: 5%;
display: flex;
align-items: center;
justify-content: center;
transition: .5s ease-in-out;
&:before, &:after {
content: '';
display: block;
transition: .1s linear;
transition-delay: .25s;
}
&:before {
width: 55%;
height: 55%;
background-image: linear-gradient(160deg, #EAB559, #ED7323);
border-radius: 50%;
}
&:after {
width: 25px;
height: 20px;
border: solid 5px white;
border-color: transparent transparent transparent white;
border-radius: 20px 0 0 50%/20px;
position: absolute;
transform: rotate(45deg);
}
}
View Compiled
let active = false;
const container = document.querySelector('[data-toggle]');
const autoPlay = setInterval(container.click.bind(container), 1500);
container.addEventListener('click', (e) => {
if (e.isTrusted && autoPlay) clearInterval(autoPlay);
e.currentTarget.dataset.active = active = !active;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.