实现如图所示的点点点loading效果:

一:CSS3 animation实现代码

html代码:

  1. 提交订单中<span class="ani_dot">...</span>

css代码:

  1. .ani_dot {
  2. font-family: simsun;
  3. }
  4. :root .ani_dot { /* 这里使用Hack是因为IE6~IE8浏览器下, vertical-align解析不规范,值为bottom或其他会改变按钮的实际高度*/
  5. display: inline-block;
  6. width: 1.5em;
  7. vertical-align: bottom;
  8. overflow: hidden;
  9. }
  10. @-webkit-keyframes dot {
  11. 0% { width:; margin-right: 1.5em; }
  12. 33% { width: .5em; margin-right: 1em; }
  13. 66% { width: 1em; margin-right: .5em; }
  14. 100% { width: 1.5em; margin-right:;}
  15. }
  16. .ani_dot {
  17. -webkit-animation: dot 3s infinite step-start;
  18. }
  19.  
  20. @keyframes dot {
  21. 0% { width:; margin-right: 1.5em; }
  22. 33% { width: .5em; margin-right: 1em; }
  23. 66% { width: 1em; margin-right: .5em; }
  24. 100% { width: 1.5em; margin-right:;}
  25. }
  26. .ani_dot {
  27. animation: dot 3s infinite step-start;
  28. }

出现的就是如图所示的结果。
注意点:

  • 1.IE10+以及其他浏览器,点点点动画消失,IE6-IE9是普通的点点点文字。
  • 2.animate动画是连续的,但是我们这儿是一帧一帧的,一卡一卡的,不是那么连续的效果,用到step-start
  • 3.上面代码还用到了css3的选择器:root。:root为IE9+以及其他现代浏览器Hack,

    IE6-7甚至IE8下,inline-block水平元素的vertical-align:bottom解析与inline水平是有差异的,会导致高度撑开,因此,display:
    inline-block要hack处理。

二:动画(animation)的参数详解

由于上面用到了animation动画,这里详细介绍下这个animation的参数。

简介

CSS动画(Animations)简单说就是在一段固定的动画时间内暗中在某一频率内改变其CSS某个或某些值,从而达到视觉上的转换动画效果。Animations的很多方面都是可以控制的,包括动画运行时间,开始值和结束值,还有动画的暂停和延迟其开始时间等。

语法

<single-animation> = <single-animation-name> || <time> || <single-animation-timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state>

<' animation-name '>:检索或设置对象所应用的动画名称
<' animation-duration '>:检索或设置对象动画的持续时间
<' animation-timing-function '>:检索或设置对象动画的过渡类型
<' animation-delay '>:检索或设置对象动画延迟的时间
<' animation-iteration-count '>:检索或设置对象动画的循环次数
<' animation-direction '>:检索或设置对象动画在循环中是否反向运动
<' animation-fill-mode '>:检索或设置对象动画时间之外的状态
<' animation-play-state '>:检索或设置对象动画的状态。w3c正考虑是否将该属性移除,因为动画的状态可以通过其它的方式实现,比如重设样式

animation

所有动画属性的简写属性,除了 animation-play-state 属性。

animation-name

规定 @keyframes 动画的名称。就是@keyframes后面跟着的动画名称,本demo本文中名为dot,意思为“点”。

animation-duration

规定动画完成一个周期所花费的秒或毫秒。默认是 0。

animation-timing-function

规定动画的速度曲线。默认是 "ease"。

常见的动画速度参数:

  1. linear:线性过渡。等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0)

  2. ease:平滑过渡。等同于贝塞尔曲线(0.25, 0.1, 0.25, 1.0)

  3. ease-in:由慢到快。等同于贝塞尔曲线(0.42, 0, 1.0, 1.0)

  4. ease-out:由快到慢。等同于贝塞尔曲线(0, 0, 0.58, 1.0)

  5. ease-in-out:由慢到快再到慢。等同于贝塞尔曲线(0.42, 0, 0.58, 1.0)

  6. step-start:等同于 steps(1, start)

  7. step-end:等同于 steps(1, end)

  8. steps(<integer>[, [ start | end ] ]?):接受两个参数的步进函数。第一个参数必须为正整数,指定函数的步数。第二个参数取值可以是start或end,指定每一步的值发生变化的时间点。第二个参数是可选的,默认值为end。

  9. cubic-bezier(<number>, <number>, <number>, <number>):特定的贝塞尔曲线类型,4个数值需在[0, 1]区间内

animation-delay

规定动画何时开始。默认是 0。也即是指动画延时执行时间。

animation-iteration-count

规定动画被播放的次数。默认是 1。当然,我们可以设置2次,3次,依次递推。还有个无线循环关键字infinite,也即是反复循环播放动画。

animation-direction

规定动画是否在下一周期逆向地播放。默认是 "normal"。当然还有下列值:

  1. reverse:反方向运行

  2. alternate:动画先正常运行再反方向运行,并持续交替运行

  3. alternate-reverse:动画先反运行再正方向运行,并持续交替运行

animation-fill-mode

规定对象动画时间之外的状态。

  1. none:默认值。不设置对象动画之外的状态

  2. forwards:设置对象状态为动画结束时的状态

  3. backwards:设置对象状态为动画开始时的状态

  4. both:设置对象状态为动画结束或开始的状态,动画开始之前是"from"或"0%"关键帧;动画完成之后是"to"或"100%"关键帧状态。

animation-play-state

规定动画是否正在运行或暂停。默认是 "running"。还有个值paused:暂停。

三:animation动画实例

实例一使用from to

  1. div{
  2. width:100px;
  3. height:100px;
  4. background:red;
  5. position:relative;
  6. animation:mymove 5s infinite;
  7. -moz-animation:mymove 5s infinite; /*Firefox*/
  8. -webkit-animation:mymove 5s infinite; /*Safari and Chrome*/
  9. }
  10. @keyframes mymove{
  11. from {left:0px;}
  12. to {left:200px;}
  13. }
  14. @-moz-keyframes mymove { /*Firefox*/
  15. from {left:0px;}
  16. to {left:200px;}
  17. }
  18. @-webkit-keyframes mymove{ /*Safari and Chrome*/
  19. from {left:0px;}
  20. to {left:200px;}
  21. }

实例二使用百分比:

  1. @keyframes myfirst{
  2. 0% {background: red; left:0px; top:0px;}
  3. 25% {background: yellow; left:200px; top:0px;}
  4. 50% {background: blue; left:200px; top:200px;}
  5. 75% {background: green; left:0px; top:200px;}
  6. 100% {background: red; left:0px; top:0px;}
  7. }
  8.  
  9. @-moz-keyframes myfirst{ /* Firefox */
  10. 0% {background: red; left:0px; top:0px;}
  11. 25% {background: yellow; left:200px; top:0px;}
  12. 50% {background: blue; left:200px; top:200px;}
  13. 75% {background: green; left:0px; top:200px;}
  14. 100% {background: red; left:0px; top:0px;}
  15. }
  16.  
  17. @-webkit-keyframes myfirst{ /* Safari 和 Chrome */
  18. 0% {background: red; left:0px; top:0px;}
  19. 25% {background: yellow; left:200px; top:0px;}
  20. 50% {background: blue; left:200px; top:200px;}
  21. 75% {background: green; left:0px; top:200px;}
  22. 100% {background: red; left:0px; top:0px;}
  23. }
  24.  
  25. @-o-keyframes myfirst {/* Opera */
  26. 0% {background: red; left:0px; top:0px;}
  27. 25% {background: yellow; left:200px; top:0px;}
  28. 50% {background: blue; left:200px; top:200px;}
  29. 75% {background: green; left:0px; top:200px;}
  30. 100% {background: red; left:0px; top:0px;}
  31. }

实例三,利用js+Transform和Animation实现3D动画

示例地址:https://webkit.org/blog-files/3d-transforms/poster-circle.html

只有webkit内核的浏览器才能看到相关3D动画效果。

实现效果如图所示:

css代码:

  1. body {
  2. font-family: 'Lucida Grande', Verdana, Arial;
  3. font-size: 12px;
  4. }
  5.  
  6. #stage {
  7. margin: 150px auto;
  8. width: 600px;
  9. height: 400px;
  10. -webkit-perspective:;
  11. }
  12.  
  13. #rotate {
  14. margin: 0 auto;
  15. width: 600px;
  16. height: 400px;
  17. -webkit-transform-style: preserve-3d;
  18. -webkit-animation-name: x-spin;
  19. -webkit-animation-duration: 7s;
  20. -webkit-animation-iteration-count: infinite;
  21. -webkit-animation-timing-function: linear;
  22. }
  23.  
  24. .ring {
  25. margin: 0 auto;
  26. height: 110px;
  27. width: 600px;
  28. -webkit-transform-style: preserve-3d;
  29. -webkit-animation-iteration-count: infinite;
  30. -webkit-animation-timing-function: linear;
  31. }
  32.  
  33. .ring > :nth-child(odd) {
  34. background-color: #995C7F;
  35. }
  36.  
  37. .ring > :nth-child(even) {
  38. background-color: #835A99;
  39. }
  40.  
  41. .poster {
  42. position: absolute;
  43. left: 250px;
  44. width: 100px;
  45. height: 100px;
  46. opacity: 0.7;
  47. color: rgba(0,0,0,0.9);
  48. -webkit-border-radius: 10px;
  49. }
  50.  
  51. .poster > p {
  52. font-family: 'Georgia', serif;
  53. font-size: 36px;
  54. font-weight: bold;
  55. text-align: center;
  56. margin-top: 28px;
  57. }
  58.  
  59. #ring-1 {
  60. -webkit-animation-name: y-spin;
  61. -webkit-animation-duration: 5s;
  62. }
  63.  
  64. #ring-2 {
  65. -webkit-animation-name: back-y-spin;
  66. -webkit-animation-duration: 4s;
  67. }
  68.  
  69. #ring-3 {
  70. -webkit-animation-name: y-spin;
  71. -webkit-animation-duration: 3s;
  72. }
  73.  
  74. @-webkit-keyframes x-spin {
  75. 0% { -webkit-transform: rotateX(0deg); }
  76. 50% { -webkit-transform: rotateX(180deg); }
  77. 100% { -webkit-transform: rotateX(360deg); }
  78. }
  79.  
  80. @-webkit-keyframes y-spin {
  81. 0% { -webkit-transform: rotateY(0deg); }
  82. 50% { -webkit-transform: rotateY(180deg); }
  83. 100% { -webkit-transform: rotateY(360deg); }
  84. }
  85.  
  86. @-webkit-keyframes back-y-spin {
  87. 0% { -webkit-transform: rotateY(360deg); }
  88. 50% { -webkit-transform: rotateY(180deg); }
  89. 100% { -webkit-transform: rotateY(0deg); }
  90. }

html代码:

  1. <div id="stage">
  2. <div id="rotate">
  3. <div id="ring-1" class="ring"></div>
  4. <div id="ring-2" class="ring"></div>
  5. <div id="ring-3" class="ring"></div>
  6. </div>
  7. </div>

js代码:

  1. const POSTERS_PER_ROW = 12;
  2. const RING_RADIUS = 200;
  3.  
  4. function setup_posters (row){
  5. var posterAngle = 360 / POSTERS_PER_ROW;
  6. for (var i = 0; i < POSTERS_PER_ROW; i ++) {
  7. var poster = document.createElement('div');
  8. poster.className = 'poster';
  9.  
  10. var transform = 'rotateY(' + (posterAngle * i) + 'deg) translateZ(' + RING_RADIUS + 'px)';
  11. poster.style.webkitTransform = transform;
  12.  
  13. var content = poster.appendChild(document.createElement('p'));
  14. content.textContent = i;
  15. row.appendChild(poster);
  16. }
  17. }
  18.  
  19. function init (){
  20. setup_posters(document.getElementById('ring-1'));
  21. setup_posters(document.getElementById('ring-2'));
  22. setup_posters(document.getElementById('ring-3'));
  23. }
  24.  
  25. window.addEventListener('load', init, false);

参考地址:
CSS参考手册:animation
小tip: CSS3 animation渐进实现点点点等待提示效果

CSS3效果:animate实现点点点loading动画效果(一)的更多相关文章

  1. CSS3效果:animate实现点点点loading动画效果(二)

    box-shadow实现的打点效果 简介 box-shadow理论上可以生成任意的图形效果,当然也就可以实现点点点的loading效果了. 实现原理 html代码,首先需要写如下html代码以及cla ...

  2. 实现loading动画效果

    下面我就来罗列三种实现loading动画效果的方法. 方法一:使用UIImageView自带的方法来实现,这也是我推荐的实现方法. NSMutableArray *array = [[NSMutabl ...

  3. ios开发之简单实现loading动画效果

    最近有朋友问我类似微信语音播放的喇叭动画和界面图片加载loading界面是怎样实现的,是不是就是一个gif图片呢!我的回答当然是否定了,当然不排除也有人用gif图片啊!下面我就来罗列三种实现loadi ...

  4. CSS3 transition实现超酷图片墙动画效果

    一.前面的感慨以前也陆陆续续试过CSS3的一些特性,文字投影,多边框等.但都是试试而已,知道有这么回事.今天,见到了一个新玩意,transition,认认真真的试了一下,经过,我懵了,我呆了,我傻了, ...

  5. Atitit Loading 动画效果

    Atitit Loading 动画效果 使用才场景,加载数据,以及显示警告灯.. 要有手动关闭按钮 <div class="spinner loading_part" sty ...

  6. [Swift通天遁地]五、高级扩展-(11)图像加载Loading动画效果的自定义和缓存

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. css3实现的3中loading动画效果

    一.css3中animation动画各种属性详解: animation Value:     [<animation-name> || <animation-duration> ...

  8. loading动画效果记录

    看到好多网页都有一个炫酷的loading动画,以前不知道怎么实现的.今天学习了一下,发现其实也很简单. 首先在学习的时候偶然遇到一个pace.js的库,非常好用.优点是,不需要挂接到任何代码,自动检测 ...

  9. javascript 通用loading动画效果

    由于项目中多处要给ajax提交的时候增加等待动画效果,所以就写了一个简单的通用js方法: 代码如下: /*ajax提交的延时等待效果*/ var AjaxLoding = new Object(); ...

随机推荐

  1. vue模式

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. PHP之ThinkPHP框架(验证码、文件上传、图片处理)

     验证码 验证码是框架自带有的,比之前使用GD库简单方便许多,其实现原理基本相似,都是生成图片,保存验证码值到Session中,表单提交验证码,然后进行值的对比验证. 简单的显示: <form ...

  3. 利用vi编辑器创建和编辑正文文件(二)

    末行模式下的命令 1.       w:写文件,将编辑的内容保存到文件系统. 2.       w!:如果只读文件,强制写入系统. 3.       q!:退出vi,但文件内容修改的话,系统要提示是否 ...

  4. List,泛型和Datatable 的相互转换

    public static DataTable ToDataTableTow(IList list) { DataTable result = new DataTable(); ) { Propert ...

  5. springBoot(4)---热部署,配置文件使用

    热部署,配置文件使用 一.热加载 spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Sprin ...

  6. VueJs(13)---过滤器

    过滤器 过滤器 1.过滤器规则 Vue.js 允许你自定义过滤器,可被用于一些常见的文本格式化.过滤器可以用在两个地方: 双花括号插值和 v-bind 表达式 (后者从 2.1.0+ 开始支持).过滤 ...

  7. ELK实践(一):基础入门

    虽然用了ELK很久了,但一直苦于没有自己尝试搭建过,所以想抽时间尝试尝试.原本打算按照教程 <ELK集中式日志平台之二 - 部署>(作者:樊浩柏科学院) 进行测试的,没想到一路出了很多坑, ...

  8. gradle 自定义插件 下载配置文件

    1.新建Gradle项目: 2.建立src/main/groovy目录,并添加如下代码: ConfigPlugin.groovy package com.wemall.config import or ...

  9. Java设计模式学习记录-模板方法模式

    前言 模板方法模式,定义一个操作中算法的骨架,而将一些步骤延迟到子类中.使得子类可以不改变一个算法的结构即可重新定义该算法的某些特定步骤. 模板方法模式 概念介绍 模板方法模式,其实是很好理解的,具体 ...

  10. JAVA课程设计——一个简单的教务人事管理系统

    大三上学期期末总结,没错,上学期,写在下学期新学期开始,哈哈哈. 上学期学习了面向对象程序设计,课程设计的题目使用JAVA语言完成一个简单的教务人事管理系统,能够实现访问数据库的登录验证,分别按部门和 ...