CSS3-实现单选框radio的小动画
在微信上看到一个教程文,觉得制作的小动画还是很有意思的,自己也试验了一下。一开始动画怎么都不执行(我用的HB),因为内置浏览器对css3的不兼容。加上各种浏览器前缀后就好了。但是旋转那个效果,在HB里还是不能正常播放。
总结就是:1,学习到了css3的伪类选择器还可以这样用!2,css3的动画设置还可以这样搭配!3,label可以替代radio。如果正常情况下让我想一个给radio
加动画的方法,我肯定不会想到把radio隐藏的!这是欲擒故纵啊。。。。
以下是代码:
<div class="radio1">
<h1>缩放动画</h1>
<input type="radio" name="ys" id="r1" />
<label for="r1"></label>
<input type="radio" name="ys" id="r2" />
<label for="r2"></label>
<input type="radio" name="ys" id="r3" />
<label for="r3"></label>
</div>
<div class="radio2">
<h1>旋转动画</h1>
<input type="radio" name="ys2" id="r4" />
<label for="r4"></label>
<input type="radio" name="ys2" id="r5" />
<label for="r5"></label>
<input type="radio" name="ys2" id="r6" />
<label for="r6"></label>
</div>
<style type="text/css">
body {
background-color: #EEEEEE;
}
h1{
color: #DC143C;
}
div {
border: 1px solid #DC143C;
border-radius: 12px;
margin-top: 10px;
padding: 10px;
text-align: center;
} .radio1 label {
display: inline-block;
position: relative;
width: 28px;
height: 28px;
border: 1px solid #ccc;
background-color: #FFF;
cursor: pointer;
border-radius: 50%;
margin-top: 10px;
}
/*核心就是把label变成了单选框的样式,把radio隐藏起来,因为选中label就会选中对应的额radio,所以用户不必直接选radio了,而是通过label变相的来选中radio。但好处就是label可以加动画样式。*/
/*给label的后边加一个动画*/ .radio1 label:after {
content: "";
position: absolute;
top: 4px;
left: 4px;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #666;
-moz-transform: scale(0);
-webkit-transform: scale(0);
-ms-transform: scale(0);
-o-transform: scale(0);
transform: scale(0);
-moz-transition: transform .5s ease-out;
-webkit-transition: transform .5s ease-out;
-o-transition: transform .5s ease-out;
-ms-transition: transform .5s ease-out;
transition: transform .5s ease-out;
}
/*把小黑点做出来,缩放为0.做出来的方法,是在label的后边加上了一个空伪类,然后填充颜色*/ .radio1 input[type="radio"]:checked+ label {
/*这既是灵活运用伪类选择器和兄弟选择器了。checked表示被选中的那个radio,+表示那个radio下边的近邻label*/
background-color: #eee;
-moz-transition: transform .2s ease-out;
-webkit-transition: transform .2s ease-out;
-ms-transition: transform .2s ease-out;
-o-transition: transform .2s ease-out;
transition: transform .2s ease-out;
} .radio1 input[type="radio"]:checked+ label:after {
-moz-transform: scale(1);
-ms-transform: scale(1);
-webkit-transform: scale(1);
-o-transform: scale(1);
transform: scale(1);
-moz-transition: transform .5s ease-out;
-webkit-transition: transform .5s ease-out;
-o-transition: transform .5s ease-out;
-ms-transition: transform .5s ease-out;
transition: transform .5s ease-out;
} .radio1 input[type="radio"] {
display: none;
}
/*radio2自己练习旋转动画*/
.radio2 label{
width: 30px;
height: 30px;
background-color: coral;
display: inline-block;
border-radius: 50%;
border: 1px solid #D2B48C;
margin-right: 5px;
position: relative;
cursor: pointer;
overflow: hidden;/*///*/
}
.radio2 label:after{
content: "";
width: 20px;
height: 20px;
background-color: #90EE90;
position: absolute;
top: 5px;
left: 5px;
border-radius: 50%;
-webkit-transform: rotate(-80deg);
-moz-transform: rotate(-180deg);
-ms-transform: rotate(-180deg);
-o-transform: rotate(-180deg);
transform: rotate(-180deg);
-webkit-transform-origin: -10px 50%;
-moz-transform-origin: -10px 50%;
-ms-transform-origin: -10px 50%;
-o-transform-origin: -10px 50%;
transform-origin: -3px 50%;
-webkit-transition: transform .7s ease-out;
-moz-transition: transform .7s ease-out;
-ms-transition: transform .7s ease-out;
-o-transition: transform .7s ease-out;
transition: transform .7s ease-out;
}
.radio2 input[type="radio"]:checked + label{
background-color: #4169E1;
-webkit-transition: background-color .7s ease-out;
-moz-transition: background-color .7s ease-out;
-ms-transition: background-color .7s ease-out;
-o-transition: background-color .7s ease-out;
transition: background-color .7s ease-out;
}
.radio2 input[type="radio"]:checked +label:after{
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
-webkit-transition: transform .7s ease-out;
-moz-transition: transform .7s ease-out;
-ms-transition: transform .7s ease-out;
-o-transition: transform .7s ease-out;
transition: transform .7s ease-out;
}
.radio2 input[type="radio"]{
display: none;
}
</style>
原文作者:千里追风,原文地址:www.jianshu.com/p/cf5b4f6b0b68(来之微信公众号:前端大全)
CSS3-实现单选框radio的小动画的更多相关文章
- 微信小程序:单选框radio和复选框CheckBox
单选框radio: 可以通过color属性来修改颜色. 复选框checkbox:
- 吾八哥学Selenium(三):操作复选框checkbox/单选框radio的方法
复选框checkbox和单选框radio是web网站里经常会使用到的两个控件,那么在web自动化测试的时候如何利用Selenium来操作这俩控件呢?今天我们就来简单入门练习一下! html测试页面代码 ...
- MFC学习单选框Radio使用
创建单选框Radio ,ID号IDC_RADIO_NAME 1.获取单选框内容 int RadioState = ((CButton *)GetDlgItem(IDC_RADIO_NAME))-> ...
- 自定义单选框radio样式
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- jquery单选框radio绑定click事件实现和是否选中的方法
使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: 1. ...
- 单选框radio总结(获取值、设置默认选中值、样式)
单选框 radio <div class="radio-inline"> <input type="radio" name="kil ...
- jquery单选框radio绑定click事件实现方法
本文实例讲述了jquery单选框radio绑定click事件实现方法.分享给大家供大家参考. 具体实现方法如下: 复制代码代码如下: <html><head><title ...
- 单选框radio改变事件详解(用的jquery的radio的change事件)
单选框radio改变事件详解(用的jquery的radio的change事件) 一.总结 1.用的jquery的radio的change事件:当元素的值发生改变时,会发生 change 事件,radi ...
- 纯CSS3来自定义单选框radio与复选框checkbox
单选框(radio)自定义样式 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...
随机推荐
- IT人员如何保护视力
最近感觉眼比较难受,有点干,估计是因为用上老婆淘汰的iPhone5C后屏幕太小,而我又是一个手机瘾重点患者的原因.为了保持自己5.0+的视力,做了以下工作,分享给各位朋友: Win7电脑将字体放大到1 ...
- js的单引号,双引号,转移符
这里我们看到想在style后边在插入一个样式的变量,data.cssSytle.a是做边和邮编都是"",并且没有转移符
- ASP.NET mvc异常处理的方法
第一种:全局异常处理 1.首先常见保存异常的类(就是将异常信息写入到文件中去) public class LogManager { private string logFilePath = strin ...
- Unix 复制文件至指定目录
cp /gaps/log/20160504/bxdx_20160504.log.Z /home 将/gaps/log/20160504/bxdx_20160504.log.Z 文件复制到home路 ...
- svn1.8 server client eclipse 插件 配置 完全教程
svn毋庸置疑,广受欢迎的版本管理软件,我们这里以1.8.10版本为例 本文分三部分 第一部分,服务器端svn安装与配置 第二部分,eclipse下svn插件安装与配置 第三部分,客户端svn简单介绍 ...
- Linux中TFTP使用详解
FTP协议简介TFTP是用来下载远程文件的最简单网络协议,它其于UDP协议而实现. linux服务器端tftp-server的配置1.安装tftp服务器需要安装xinetd(守护tftp).tftp和 ...
- [转]fastjson常见问题
转自fastjson wiki说明文档:https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98 1. ...
- 简单解决ListView和ScrollView冲突,复杂情况仅供参考
ScrollView嵌套ListView冲突问题的最优解决方案 (转) 记录学习之用 项目做多了之后,会发现其实 ScrollView嵌套ListVew或者GridView等很常用,但是你也会发现各种 ...
- Django-Model 使用
添加 更改 删除 查找 /1 使用get 方式查找,只有一条数据,并如果数据不存在的时候会报错,建议不用 User.objects.get(uname=xxx) User. 模型 get(uname= ...
- Arraylist Vector Linkedlist区别和用法 (转)
ArrayList 和Vector是采用数组方式存储数据,此数组元素数大于实际存储的数据以便增加和插入元素,都允许直接序号索引元素,但是插入数据要设计到数组元素移动等内存操作,所以索引数据快插入数据慢 ...