动画animation的三个应用(漂浮的白云、旋转的星球、正方体合成)
前面的话
前面介绍过动画animation的详细用法,本文主要介绍动画animation的三个效果
漂浮的白云
【效果演示】
【简要介绍】
漂浮的白云主要通过远景白云和近景白云来实现立体漂浮效果。远景和近景分别使用两张背景图片,通过改变其背景定位来实现白云移动效果,通过设置不同的动画持续时间来实现交错漂浮的效果
【主要代码】
- .box{
- position: relative;
- height: 300px;
- width: 500px;
- }
- .in1,.in2{
- position: absolute;
- height: 100%;
- width: 100%;
- background-size:cover;
- animation: move 100s infinite linear alternate;
- }
- @keyframes move{
- 100%{background-position: 500% 0;}
- }
- .in1{
- background-image: url('http://sandbox.runjs.cn/uploads/rs/26/ddzmgynp/cloud.png');
- }
- .in2{
- background-image: url('http://sandbox.runjs.cn/uploads/rs/26/ddzmgynp/cloud1.png');
- animation-duration: 10s;
- }
- <div class="box">
- <div class="in1"></div>
- <div class="in2"></div>
- </div>
旋转的星球
【效果演示】
【简要介绍】
旋转的星球主要通过rotate()旋转函数来实现。实际上,蓝色的地球和黑色的月球并没有发生旋转,只是其父级旋转形成的视觉上的旋转效果
【代码演示】
- .box{
- transform: scale(0.5);
- position: relative;
- padding: 1px;
- height: 300px;
- width: 300px;
- }
- .sunline{
- position:relative;
- height: 400px;
- width: 400px;
- border: 2px solid black;
- border-radius: 50%;
- margin: 50px 0 0 50px;
- display: flex;
- animation: rotate 10s infinite linear;
- }
- .sun{
- height: 100px;
- width: 100px;
- margin: auto;
- background-color: red;
- border-radius: 50%;
- box-shadow: 5px 5px 10px red,-5px -5px 10px red,5px -5px 10px red,-5px 5px 10px red;
- }
- .earthline{
- position: absolute;
- right:;
- top: 50%;
- height: 200px;
- width: 200px;
- margin: -100px -100px 0 0;
- border: 1px solid black;
- border-radius: 50%;
- display: flex;
- animation: rotate 2s infinite linear;
- }
- .earth{
- margin: auto;
- height: 50px;
- width: 50px;
- background-color: blue;
- border-radius: 50%;
- }
- .moon{
- position: absolute;
- left:;
- top: 50%;
- height: 20px;
- width: 20px;
- margin: -10px 0 0 -10px;
- background-color: black;
- border-radius: 50%;
- }
- @keyframes rotate{
- 100%{transform:rotate(360deg);}
- }
- <div class="box">
- <div class="sunline">
- <div class="sun"></div>
- <div class="earthline">
- <div class="earth"></div>
- <div class="moon"></div>
- </div>
- </div>
- </div>
【进阶使用】
如果要在内侧旋转的球内放文本,并且文本不跟着旋转,则代码如下
- @keyframes spin{100%{transform:rotate(1turn);}}
- .outer{width: 100px;height: 100px;background-color: pink;border-radius: 50%;animation: spin 3s linear infinite;animation-play-state:running;text-align: center;}
- .inner{width: 40px;height: 40px;line-height:40px;background-color: tan;border-radius: 50%;animation: inherit;animation-direction:reverse;}
- div:hover,div:focus{
- animation-play-state:paused;
- }
鼠标移入后,动画停止;移出时,动画继续
正方体合成
【效果演示】
【简要介绍】
该效果主要通过设置计算后的延迟时间来达到正方体的各个边顺序动画的效果。一次动画结束后,通过触发animationend事件重置animation-name来实现重复动画的效果
【代码演示】
- ul{
- margin:;
- padding:;
- list-style: none;
- }
- .box{
- height: 100px;
- width: 100px;
- perspective: 500px;
- margin: 50px 0 0 50px;
- }
- .list{
- position: relative;
- height: 100px;
- width: 100px;
- background-color: blue;
- transform-style: preserve-3d;
- transform-origin: 0 0 0;
- animation: rotate 1s 10s 3 both linear;
- }
- .in{
- position: absolute;
- height: 100px;
- width: 100px;
- }
- .list .in:nth-child(6){
- background-color: pink;
- transform-origin: top;
- animation: in6 2s both;
- }
- .list .in:nth-child(5){
- background-color: lightgreen;
- transform-origin: right;
- animation: in5 2s 2s both;
- }
- .list .in:nth-child(4){
- background-color: lightblue;
- transform-origin: bottom;
- animation: in4 2s 4s both;
- }
- .list .in:nth-child(3){
- background-color: lightcoral;
- transform-origin: left;
- animation: in3 2s 6s both;
- }
- .list .in:nth-child(2){
- background-color: lightcyan;
- animation: in2 2s 8s both;
- }
- .list .in:nth-child(1){background-color: lightsalmon;}
- .box:hover .list{animation-play-state: paused;}
- .box:hover .in{animation-play-state: paused;}
- @keyframes in6{100%{transform: rotateX(90deg);}}
- @keyframes in5{100%{transform: rotateY(90deg);}}
- @keyframes in4{100%{transform: rotateX(-90deg);}}
- @keyframes in3{100%{transform: rotateY(-90deg);}}
- @keyframes in2{100%{transform: translateZ(100px);}}
- @keyframes rotate{100%{transform: rotate3d(1,1,1,360deg);}}
- <div class="box">
- <ul class="list" id="list">
- <li class="in"></li>
- <li class="in"></li>
- <li class="in"></li>
- <li class="in"></li>
- <li class="in"></li>
- <li class="in"></li>
- </ul>
- </div>
- list.addEventListener('animationend',function(e){
- e = e || event;
- var target = e.target || e.srcElement;
- if(target.nodeName == 'UL'){
- list.style.animationName = 'none';
- var children = list.getElementsByTagName('li');
- for(var i = 0; i < children.length;i++){
- children[i].style.animationName = 'none';
- }
- setTimeout(function(){
- list.style.animationName = 'rotate';
- var children = list.getElementsByTagName('li');
- for(var i = 0; i < children.length;i++){
- children[i].style.animationName = 'in' + (i+1);
- }
- },100);
- }
- },false);
动画animation的三个应用(漂浮的白云、旋转的星球、正方体合成)的更多相关文章
- CSS3的变形transform、过渡transition、动画animation学习
学习CSS3动画animation得先了解一些关于变形transform.过渡transition的知识 这些新属性大多在新版浏览器得到了支持,有些需要添加浏览器前缀(-webkit-.-moz-.- ...
- css3中的变形(transform)、过渡(transtion)、动画(animation)
Transform字面上就是变形,改变的意思.在CSS3中transform主要包括以下几种:旋转rotate.扭曲skew.缩放scale和移动translate以及矩阵变形matrix.下面我们一 ...
- 精灵动画Animation对话框组成Idle动画的各精灵
精灵动画Animation对话框组成Idle动画的各精灵 1.3 精灵动画 场景中已经添加了精灵,现在是时候让让它动起来了.读者也许已经从精灵图集中,各精灵的命名中看出来了,这个精灵一共有两种动画状 ...
- Qt-4.6动画Animation快速入门三字决
Qt-4.6动画Animation快速入门三字决 Qt-4.6新增了Animation Framework(动画框架),让我们能够方便的写一些生动的程序.不必像以前的版本一样,所有的控件都枯燥的呆在伟 ...
- css3 动画(animation)-简单入门
css3之动画(animation) css3中我们可以使用动画,由于取代以前的gif图片,flash动画,以及部分javascript代码(相信有很多同学都用过jquery中的animate方法来做 ...
- View 动画 Animation 运行原理解析
这次想来梳理一下 View 动画也就是补间动画(ScaleAnimation, AlphaAnimation, TranslationAnimation...)这些动画运行的流程解析.内容并不会去分析 ...
- Android学习之Animation(三)
今天观看了一个关于android动画的一些知识,就顺便记录下来,以备之后的学习和参考. 在XML文件中使用LayoutAnimationController 第一步: 在res/anim文件夹下创建一 ...
- CSS3动画属性:动画(animation)
一:动画(animation)的参数详解 由于上面用到了animation动画,这里详细介绍下这个animation的参数. 简介 CSS动画(Animations)简单说就是在一段固定的动画时间内暗 ...
- 《The Cg Tutorial》阅读笔记——动画 Animation
这段时间阅读了英文版的NVidia官方的<The Cg Tutorial>,借此来学习基本的图形学知识和着色器编程. 在此做一个阅读笔记. 本文为大便一箩筐的原创内容,转载请注明出处,谢谢 ...
随机推荐
- C#与Swift异步操作的差异
作为一个从C#转到Swift的小菜鸡...最近做一个简单的请求API解析Json数据的小程序上碰到一堆小问题.尤其是在异步请求的时候,用惯了C#的async/await写法,在写Swift的时候也按着 ...
- mySQL中删除unique key的语法
CREATE TABLE `good_booked` ( `auto_id` int(10) NOT NULL auto_increment, `good_id` int(11) default ...
- DSO动态加载PHP模块到Apache服务器
PHP在Linux/Unix平台上经常与Apache搭配使用,在安装PHP时,有三种安装方式可供选择:静态模式.动态模式(DSO).CGI二进制模式. 由于易于维护和升级,我强烈建议以DSO方式安装P ...
- mysql 条件统计
问题描述为使讨论简单易懂,我将问题稍作简化,去掉诸多的背景. 从前有一个皇帝,他有50个妃子,这些妃子很没有天理的给他生了100,000个儿子,于是,皇帝很苦恼,海量的儿子很难管理,而且,他想知道每个 ...
- HashSet和HapMap取distinct value
public class TestHashSetAndHashMap { private final int setNum=5000; @Test public void doTest(){ List ...
- Constructing Roads In JGShining's Kingdom(HDU1025)(LCS序列的变行)
Constructing Roads In JGShining's Kingdom HDU1025 题目主要理解要用LCS进行求解! 并且一般的求法会超时!!要用二分!!! 最后蛋疼的是输出格式的注 ...
- oracle 11g install linux
#!/bin/bash#Purpose:Create and config oracle install.#Usage:Log on as the superuser('root') #1.creat ...
- 如何保证DBContext实例上下文唯一
using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using S ...
- .NET JSON对象序列化和反序列化
class Program { static void Main(string[] args) { Console.WriteLine("========================== ...
- 【转】Backbone标准例子——通讯录
参考:http://z2009zxiaolong.iteye.com/blog/1847833 感觉不错的例子,模型.视图.路由等知识点都用到了:),将此文中的源码转载如下: http://dmyz. ...