开关处的边框动画不会随着位置的变化而起作用。禁用时, animation: rotation 1s linear infinite;滑块会移动
@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
input{
position: relative;
-webkit-appearance:none;
width: 60px;
height: 6px;
background: #e4e4e4;
border-radius: 5px;
cursor: pointer;
}
input:before{
content: "";
position: absolute;
top:-12px;
left:0;
width: 30px;
height: 30px;
background:#ccc;
border-radius: 50%;
transition: 0.5s;
border:1px solid #ccc;
}
input:checked:before{
transform: translateX(30px);
background:#ffbd45;
border: 1px solid #ffbd45;
border-bottom-color: #FF3D00;
//animation: rotation 1s linear infinite;
}
input.c1:checked:after{
width:0;
border-radius: 10px;
left:20%;
transform: translate(30px,-50%);
}
<input type="checkbox">
如果你想让动画播放的同时移动滑块,那么你需要添加滑块的最终位置
并且不要忘记注释是用 CSS 设计的
/*code*/问题是您覆盖了动画中的transform属性的值,但是您需要以相同的顺序指定应用于元素的整个转换集,同时仅更改必要的值。
幸运的是,最近独立管理转换已经成为可能: