首先,先介绍一下主要用到的css属性:animation,text-shadow。

  text-shadow就不再介绍了,上一篇已经详细介绍了用法。这里先介绍一下animation属性。

1.animation

  animation是css3的属性,主要有以下几项:

属性 描述  
@keyframes 规定动画。  
animation 所有动画属性的简写属性,除了 animation-play-state 属性。  
animation-name 规定 @keyframes 动画的名称。  
animation-duration 规定动画完成一个周期所花费的秒或毫秒。默认是 0。  
animation-timing-function 规定动画的速度曲线。默认是 "ease"。  
animation-delay 规定动画何时开始。默认是 0。  
animation-iteration-count 规定动画被播放的次数。默认是 1。  
animation-direction 规定动画是否在下一周期逆向地播放。默认是 "normal"。  
animation-play-state 规定动画是否正在运行或暂停。默认是 "running"。  
animation-fill-mode 规定对象动画时间之外的状态。  

指定动画和播放的速度时间等相关设置。

2.keyframes

  关键帧是css动画的另一个重要属性。要设置动画必须指定要关键帧。 

  用百分比来规定变化发生的时间,或用关键词 "from" 和 "to",等同于 0% 和 100%。0% 是动画的开始,100% 是动画的完成,我们也可以设置好0-100中间的各个时间阶段的样式。比如这里,我们指定了首尾两个节点的样式:

 @keyframes ani1 {
from {
text-shadow: 0 0 10px #fff,0 0 20px #fff,0 0 30px #fff, 0 0 40px #ff1177, 0 0 70px #ff1177, 0 0 80px #ff1177, 0 0 150px #ff1177;
}
to {
text-shadow: 0 0 5px #fff,0 0 15px #fff,0 0 20px #fff, 0 0 30px #ff1177, 0 0 40px #ff1177, 0 0 50px #ff1177, 0 0 60px #ff1177;
}
}

其原理,就是利用text-shadow的渐变过渡结合动画,来实现呼吸灯的亮暗效果。

  我们可以设置更准确的百分比样式,如:

 @keyframes myfirst
{
0% {background: red;}
25% {background: yellow;}
50% {background: blue;}
100% {background: green;}
}

3.结合使用

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style type="text/css">
body {
font-weight: 400;
background-color: black;
text-align: center;
}
a {
font-size: 7em;
text-decoration: none;
}
p:nth-child(1) a {
color: #FF1177;
}
p:nth-child(1) a:hover {
color: white;
animation: ani1 1s ease-in-out infinite alternate;
-webkit-animation: ani1 1s ease-in-out infinite alternate;
-moz-animation: ani1 1s ease-in-out infinite alternate;
}
@keyframes ani1 {
from {
text-shadow: 0 0 10px #fff,0 0 20px #fff,0 0 30px #fff, 0 0 40px #ff1177, 0 0 70px #ff1177, 0 0 80px #ff1177, 0 0 150px #ff1177;
}
to {
text-shadow: 0 0 5px #fff,0 0 15px #fff,0 0 20px #fff, 0 0 30px #ff1177, 0 0 40px #ff1177, 0 0 50px #ff1177, 0 0 60px #ff1177;
}
}
@-webkit-keyframes ani1 {
from {
text-shadow: 0 0 10px #fff,0 0 20px #fff,0 0 30px #fff, 0 0 40px #ff1177, 0 0 70px #ff1177, 0 0 80px #ff1177, 0 0 150px #ff1177;
}
to {
text-shadow: 0 0 5px #fff,0 0 15px #fff,0 0 20px #fff, 0 0 30px #ff1177, 0 0 40px #ff1177, 0 0 50px #ff1177, 0 0 60px #ff1177;
}
}
@-moz-keyframes ani1 {
from {
text-shadow: 0 0 10px #fff,0 0 20px #fff,0 0 30px #fff, 0 0 40px #ff1177, 0 0 70px #ff1177, 0 0 80px #ff1177, 0 0 150px #ff1177;
}
to {
text-shadow: 0 0 5px #fff,0 0 15px #fff,0 0 20px #fff, 0 0 30px #ff1177, 0 0 40px #ff1177, 0 0 50px #ff1177, 0 0 60px #ff1177;
}
}
</style>
</head>
<body>
<div id="container">
<p><a href="#">
RED
</a></p>
</div>
</body>
</html>

  需要注意的是,由于存在浏览器兼容性,IE9以上和谷歌火狐等才支持。因而写样式的时候,keyframes和animation需要使用谷歌和火狐的前缀来进行兼容:-webkit-,-moz-

最新文章

  1. TCP三次握手图解
  2. cefglue埋坑记录
  3. python之旅3
  4. 创建自己的Activity
  5. NSString、NSArray、NSDictionary和NSData的数据存储
  6. Linux下如何查看tomcat是否启动
  7. 你不需要jQuery(五)
  8. 一种基于Storm的可扩展即时数据处理架构思考
  9. Java学习笔记(1)——基本数据类型
  10. CocoaPod安装
  11. WindowProc和DefWindowProc的区别
  12. 开发一个微信小程序教程
  13. VMware 全虚拟打开
  14. CharacterController平滑移动到某点
  15. React Native之图片保存到本地相册(ios android)
  16. Java Web(四) 一次性验证码的代码实现
  17. 使用Apache php 的一些基本操作(一)
  18. android 拍照声音文件路径
  19. MongoDB 2.4企业版分析
  20. java使用AES256解密

热门文章

  1. MongoDB安装与使用体验
  2. 如何在你的项目中集成 CAP【手把手视频教程】
  3. 做自己的CEO
  4. Servlet生命周期 、Filter生命周期、Listering(监听器)总结
  5. 使用sklearn时cannot import name MLPClassifier的解决办法
  6. 1.3创建项目「深入浅出ASP.NET Core系列」
  7. 一次 C# 查詢數據庫 算法優化的案例
  8. 第一册:lesson 121.
  9. 用jQuery实现切换动态图片
  10. Java并发编程实战 之 对象的共享