前面的话

  前面介绍过动画animation的详细用法,本文主要介绍动画animation的三个效果

漂浮的白云

【效果演示】

【简要介绍】

  漂浮的白云主要通过远景白云和近景白云来实现立体漂浮效果。远景和近景分别使用两张背景图片,通过改变其背景定位来实现白云移动效果,通过设置不同的动画持续时间来实现交错漂浮的效果

【主要代码】

  1. .box{
  2. position: relative;
  3. height: 300px;
  4. width: 500px;
  5. }
  6. .in1,.in2{
  7. position: absolute;
  8. height: 100%;
  9. width: 100%;
  10. background-size:cover;
  11. animation: move 100s infinite linear alternate;
  12. }
  13. @keyframes move{
  14. 100%{background-position: 500% 0;}
  15. }
  16. .in1{
  17. background-image: url('http://sandbox.runjs.cn/uploads/rs/26/ddzmgynp/cloud.png');
  18. }
  19. .in2{
  20. background-image: url('http://sandbox.runjs.cn/uploads/rs/26/ddzmgynp/cloud1.png');
  21. animation-duration: 10s;
  22. }
  1. <div class="box">
  2. <div class="in1"></div>
  3. <div class="in2"></div>
  4. </div>

源码查看

旋转的星球

【效果演示】

【简要介绍】

  旋转的星球主要通过rotate()旋转函数来实现。实际上,蓝色的地球和黑色的月球并没有发生旋转,只是其父级旋转形成的视觉上的旋转效果

【代码演示】

  1. .box{
  2. transform: scale(0.5);
  3. position: relative;
  4. padding: 1px;
  5. height: 300px;
  6. width: 300px;
  7. }
  8. .sunline{
  9. position:relative;
  10. height: 400px;
  11. width: 400px;
  12. border: 2px solid black;
  13. border-radius: 50%;
  14. margin: 50px 0 0 50px;
  15. display: flex;
  16. animation: rotate 10s infinite linear;
  17. }
  18. .sun{
  19. height: 100px;
  20. width: 100px;
  21. margin: auto;
  22. background-color: red;
  23. border-radius: 50%;
  24. box-shadow: 5px 5px 10px red,-5px -5px 10px red,5px -5px 10px red,-5px 5px 10px red;
  25. }
  26. .earthline{
  27. position: absolute;
  28. right:;
  29. top: 50%;
  30. height: 200px;
  31. width: 200px;
  32. margin: -100px -100px 0 0;
  33. border: 1px solid black;
  34. border-radius: 50%;
  35. display: flex;
  36. animation: rotate 2s infinite linear;
  37. }
  38. .earth{
  39. margin: auto;
  40. height: 50px;
  41. width: 50px;
  42. background-color: blue;
  43. border-radius: 50%;
  44. }
  45. .moon{
  46. position: absolute;
  47. left:;
  48. top: 50%;
  49. height: 20px;
  50. width: 20px;
  51. margin: -10px 0 0 -10px;
  52. background-color: black;
  53. border-radius: 50%;
  54. }
  55. @keyframes rotate{
  56. 100%{transform:rotate(360deg);}
  57. }
  1. <div class="box">
  2. <div class="sunline">
  3. <div class="sun"></div>
  4. <div class="earthline">
  5. <div class="earth"></div>
  6. <div class="moon"></div>
  7. </div>
  8. </div>
  9. </div>

源码查看

【进阶使用】

  如果要在内侧旋转的球内放文本,并且文本不跟着旋转,则代码如下

  1. @keyframes spin{100%{transform:rotate(1turn);}}
  2. .outer{width: 100px;height: 100px;background-color: pink;border-radius: 50%;animation: spin 3s linear infinite;animation-play-state:running;text-align: center;}
  3. .inner{width: 40px;height: 40px;line-height:40px;background-color: tan;border-radius: 50%;animation: inherit;animation-direction:reverse;}
  4. div:hover,div:focus{
  5. animation-play-state:paused;
  6. }

  鼠标移入后,动画停止;移出时,动画继续

正方体合成

【效果演示】

【简要介绍】

  该效果主要通过设置计算后的延迟时间来达到正方体的各个边顺序动画的效果。一次动画结束后,通过触发animationend事件重置animation-name来实现重复动画的效果

【代码演示】

  1. ul{
  2. margin:;
  3. padding:;
  4. list-style: none;
  5. }
  6. .box{
  7. height: 100px;
  8. width: 100px;
  9. perspective: 500px;
  10. margin: 50px 0 0 50px;
  11. }
  12. .list{
  13. position: relative;
  14. height: 100px;
  15. width: 100px;
  16. background-color: blue;
  17. transform-style: preserve-3d;
  18. transform-origin: 0 0 0;
  19. animation: rotate 1s 10s 3 both linear;
  20. }
  21. .in{
  22. position: absolute;
  23. height: 100px;
  24. width: 100px;
  25. }
  26. .list .in:nth-child(6){
  27. background-color: pink;
  28. transform-origin: top;
  29. animation: in6 2s both;
  30. }
  31. .list .in:nth-child(5){
  32. background-color: lightgreen;
  33. transform-origin: right;
  34. animation: in5 2s 2s both;
  35. }
  36. .list .in:nth-child(4){
  37. background-color: lightblue;
  38. transform-origin: bottom;
  39. animation: in4 2s 4s both;
  40. }
  41. .list .in:nth-child(3){
  42. background-color: lightcoral;
  43. transform-origin: left;
  44. animation: in3 2s 6s both;
  45. }
  46. .list .in:nth-child(2){
  47. background-color: lightcyan;
  48. animation: in2 2s 8s both;
  49. }
  50. .list .in:nth-child(1){background-color: lightsalmon;}
  51. .box:hover .list{animation-play-state: paused;}
  52. .box:hover .in{animation-play-state: paused;}
  53. @keyframes in6{100%{transform: rotateX(90deg);}}
  54. @keyframes in5{100%{transform: rotateY(90deg);}}
  55. @keyframes in4{100%{transform: rotateX(-90deg);}}
  56. @keyframes in3{100%{transform: rotateY(-90deg);}}
  57. @keyframes in2{100%{transform: translateZ(100px);}}
  58. @keyframes rotate{100%{transform: rotate3d(1,1,1,360deg);}}
  1. <div class="box">
  2. <ul class="list" id="list">
  3. <li class="in"></li>
  4. <li class="in"></li>
  5. <li class="in"></li>
  6. <li class="in"></li>
  7. <li class="in"></li>
  8. <li class="in"></li>
  9. </ul>
  10. </div>
  1. list.addEventListener('animationend',function(e){
  2. e = e || event;
  3. var target = e.target || e.srcElement;
  4. if(target.nodeName == 'UL'){
  5. list.style.animationName = 'none';
  6. var children = list.getElementsByTagName('li');
  7. for(var i = 0; i < children.length;i++){
  8. children[i].style.animationName = 'none';
  9. }
  10. setTimeout(function(){
  11. list.style.animationName = 'rotate';
  12. var children = list.getElementsByTagName('li');
  13. for(var i = 0; i < children.length;i++){
  14. children[i].style.animationName = 'in' + (i+1);
  15. }
  16. },100);
  17. }
  18. },false);

源码查看

动画animation的三个应用(漂浮的白云、旋转的星球、正方体合成)的更多相关文章

  1. CSS3的变形transform、过渡transition、动画animation学习

    学习CSS3动画animation得先了解一些关于变形transform.过渡transition的知识 这些新属性大多在新版浏览器得到了支持,有些需要添加浏览器前缀(-webkit-.-moz-.- ...

  2. css3中的变形(transform)、过渡(transtion)、动画(animation)

    Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix.下面我们一 ...

  3. 精灵动画Animation对话框组成Idle动画的各精灵

    精灵动画Animation对话框组成Idle动画的各精灵 1.3  精灵动画 场景中已经添加了精灵,现在是时候让让它动起来了.读者也许已经从精灵图集中,各精灵的命名中看出来了,这个精灵一共有两种动画状 ...

  4. Qt-4.6动画Animation快速入门三字决

    Qt-4.6动画Animation快速入门三字决 Qt-4.6新增了Animation Framework(动画框架),让我们能够方便的写一些生动的程序.不必像以前的版本一样,所有的控件都枯燥的呆在伟 ...

  5. css3 动画(animation)-简单入门

    css3之动画(animation) css3中我们可以使用动画,由于取代以前的gif图片,flash动画,以及部分javascript代码(相信有很多同学都用过jquery中的animate方法来做 ...

  6. View 动画 Animation 运行原理解析

    这次想来梳理一下 View 动画也就是补间动画(ScaleAnimation, AlphaAnimation, TranslationAnimation...)这些动画运行的流程解析.内容并不会去分析 ...

  7. Android学习之Animation(三)

    今天观看了一个关于android动画的一些知识,就顺便记录下来,以备之后的学习和参考. 在XML文件中使用LayoutAnimationController 第一步: 在res/anim文件夹下创建一 ...

  8. CSS3动画属性:动画(animation)

    一:动画(animation)的参数详解 由于上面用到了animation动画,这里详细介绍下这个animation的参数. 简介 CSS动画(Animations)简单说就是在一段固定的动画时间内暗 ...

  9. 《The Cg Tutorial》阅读笔记——动画 Animation

    这段时间阅读了英文版的NVidia官方的<The Cg Tutorial>,借此来学习基本的图形学知识和着色器编程. 在此做一个阅读笔记. 本文为大便一箩筐的原创内容,转载请注明出处,谢谢 ...

随机推荐

  1. C#与Swift异步操作的差异

    作为一个从C#转到Swift的小菜鸡...最近做一个简单的请求API解析Json数据的小程序上碰到一堆小问题.尤其是在异步请求的时候,用惯了C#的async/await写法,在写Swift的时候也按着 ...

  2. mySQL中删除unique key的语法

    CREATE TABLE `good_booked` (  `auto_id` int(10) NOT NULL auto_increment,  `good_id` int(11) default ...

  3. DSO动态加载PHP模块到Apache服务器

    PHP在Linux/Unix平台上经常与Apache搭配使用,在安装PHP时,有三种安装方式可供选择:静态模式.动态模式(DSO).CGI二进制模式. 由于易于维护和升级,我强烈建议以DSO方式安装P ...

  4. mysql 条件统计

    问题描述为使讨论简单易懂,我将问题稍作简化,去掉诸多的背景. 从前有一个皇帝,他有50个妃子,这些妃子很没有天理的给他生了100,000个儿子,于是,皇帝很苦恼,海量的儿子很难管理,而且,他想知道每个 ...

  5. HashSet和HapMap取distinct value

    public class TestHashSetAndHashMap { private final int setNum=5000; @Test public void doTest(){ List ...

  6. Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)

    Constructing Roads In JGShining's Kingdom  HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...

  7. oracle 11g install linux

    #!/bin/bash#Purpose:Create and config oracle install.#Usage:Log on as the superuser('root') #1.creat ...

  8. 如何保证DBContext实例上下文唯一

    using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using S ...

  9. .NET JSON对象序列化和反序列化

    class Program { static void Main(string[] args) { Console.WriteLine("========================== ...

  10. 【转】Backbone标准例子——通讯录

    参考:http://z2009zxiaolong.iteye.com/blog/1847833 感觉不错的例子,模型.视图.路由等知识点都用到了:),将此文中的源码转载如下: http://dmyz. ...