这是一款效果非常炫酷的纯CSS3 Material Design风格单选按钮和复选框动画特效。该特效使用CSS帧动画来在单选按钮或复选框被选择时制作类似于按钮点击波的效果。它的代码简洁,效果非常的出色。
遗憾的是,目前只有谷歌浏览器支持这一特效,在不支持该特效的浏览器上,单选按钮和复选框也被进行了一些美化,整体还是不错的。
使用方法
HTML结构
该特效的复选框和单选按钮的HTML结构都是使用一个标签来包裹一个元素。
Checkbox
Radio option
CSS样式
单选按钮和复选框的基本样式如下,其中::before伪元素用于制作单选按钮和复选框中的小叉,::after伪元素用于制作点击波动画效果。
.option-input {
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
position: relative;
top: 13.33333px;
width: 40px;
height: 40px;
-webkit-transition: all 0.15s ease-out 0;
-moz-transition: all 0.15s ease-out 0;
transition: all 0.15s ease-out 0;
background: #cbd1d8;
border: none;
color: #fff;
cursor: pointer;
display: inline-block;
outline: none;
position: relative;
margin-right: 0.5rem;
z-index: 1000;
}
.option-input:hover { background: #9faab7; }
.option-input:checked { background: #40e0d0; }
.option-input:checked::before {
width: 40px;
height: 40px;
position: absolute;
content: '\2716';
display: inline-block;
font-size: 26.66667px;
text-align: center;
line-height: 40px;
}
.option-input:checked::after {
-webkit-animation: click-wave 0.65s;
-moz-animation: click-wave 0.65s;
animation: click-wave 0.65s;
background: #40e0d0;
content: '';
display: block;
position: relative;
z-index: 100;
}
.option-input.radio { border-radius: 50%; }
.option-input.radio::after { border-radius: 50%; }
然后使用CSS keyframe来制作Material Design风格的按钮点击波特效。
@-webkit-keyframes
click-wave { 0% {
width: 40px;
height: 40px;
opacity: 0.35;
position: relative;
}
100% {
width: 200px;
height: 200px;
margin-left: -80px;
margin-top: -80px;
opacity: 0.0;
}
}
@-moz-keyframes
click-wave { 0% {
width: 40px;
height: 40px;
opacity: 0.35;
position: relative;
}
100% {
width: 200px;
height: 200px;
margin-left: -80px;
margin-top: -80px;
opacity: 0.0;
}
}
@-o-keyframes
click-wave { 0% {
width: 40px;
height: 40px;
opacity: 0.35;
position: relative;
}
100% {
width: 200px;
height: 200px;
margin-left: -80px;
margin-top: -80px;
opacity: 0.0;
}
}
@keyframes
click-wave { 0% {
width: 40px;
height: 40px;
opacity: 0.35;
position: relative;
}
100% {
width: 200px;
height: 200px;
margin-left: -80px;
margin-top: -80px;
opacity: 0.0;
}
}