I want to use input:checked
selector to control animation execution and return
Expected result
div {
position: absolute;
bottom: -46px;
right: -100px;
transform: scale(0);
overflow: hidden;
width: 300px;
height: 150px;
background-color: #369;
}
@keyframes run {
0% {
transform: scale(0);
}
60% {
right: 40%;
bottom: 60%;
}
100% {
transform: scale(1);
right: 40%;
bottom: 60%;
}
}
input {
position: absolute;
bottom: 20px;
right: 40px;
}
input:checked + div {
animation: run 1s ease-in infinite;
animation-direction: alternate;
}
<input type="checkbox">
<div></div>
When :checked
, the animation is executed to the last frame and retained
When canceling :checked
, it should return to the animation reduction
div {
position: absolute;
bottom: -46px;
right: -100px;
transform: scale(0);
overflow: hidden;
width: 300px;
height: 150px;
background-color: #369;
}
@keyframes run {
0% {
transform: scale(0);
}
60% {
right: 40%;
bottom: 60%;
}
100% {
transform: scale(1);
right: 40%;
bottom: 60%;
}
}
input {
width: 50px;
height: 50px;
position: absolute;
bottom: 20px;
right: 40px;
}
input:checked + div {
animation: run 1s ease-in both;
}
<input type="checkbox">
<div></div>