我正在为一个网站制作一个复选框切换滑块,我得到了复选框滑动时,其选中,但我不知道如何使它顺利滑回原来的位置。任何帮助将不胜感激!!
#spherewishlist
{
height:40px;
width:70px;
background-color:gray;
border-radius:40px;
display: block;
border-color: white;
}
#circlewishlist
{
height:36px;
width:40px;
background-color:white;
border-radius:100%;
display: block;
box-shadow: 0px 1px 1px #141414;
position:relative;
margin-left:3px;
content:url('white-circle-frame-with-shadow-free-png.png');
appearance:none;
top:41px;
}
#circlewishlist:checked
{ animation-name:slidewish;
animation-duration: 1s;
right:-24px;
}
#circlewishlist:checked + #spherewishlist
{background-color:green;}
@keyframes slidewish
{ 0%{left:0px;}
100%{left:24px;}
}
这是HTML
<div>
<input id="circlewishlist" type="checkbox"><!-- this is the circle-->
<div id="spherewishlist"></div><!-- this is the sphere-->
</div>
1条答案
按热度按时间vfhzx4xs1#
我个人使用
transform
而不是@keyframes
,我发现这对于简单的动画来说更容易: