动画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#的对象赋值
例如 Class A { int x = 0; int y = 0; } public void test() { A test1 = new A( ); ...
- struts2中jsp前台传值到后台action的方法(转)
在Struts2中jsp前台传值到action后台的方法 分类: java2012-02-28 13:58 2171人阅读 评论(1) 收藏 举报 actionstrutsjspgetterstrin ...
- android简单登陆和注册功能实现+SQLite数据库学习
最近初学android,做了实验室老师给的基本任务,就是简单的登陆和注册,并能通过SQLite实现登陆,SQlLite是嵌入在安卓设备中的 好了下面是主要代码: 数据库的建立: 这里我只是建立了一个用 ...
- [转]单点登录SSO学习——CAS协议内容
作者:anmaler 本文转自:http://blog.zhaojunling.me/p/24 CAS中文文档甚少,这篇文章对CAS接口参数有比较清楚的说明,排版也不错查阅舒适 在当前互联网产品中使用 ...
- 推荐几款自己写博客使用的Ubuntu软件
使用Ubuntu桌面有段时间,到现在也写过几篇博客了,期间用到的几款好用的软件推荐给大家.1. 图片简单编辑软件gthumbubuntu默认提供shotwell查看图片,类似与windows的图片查看 ...
- Backbone源码解析(五):Route和History(路由)模块
今天是四月十二号,距离上次写博已经将近二十天了.一直忙于工作,回家被看书的时间占用了.连续两个礼拜被频繁的足球篮球以及各种体育运动弄的精疲力竭,所以很少抽时间来写技术博客.今天抽出时间把backbon ...
- Python黑客编程基础3网络数据监听和过滤
网络数据监听和过滤 课程的实验环境如下: • 操作系统:kali Linux 2.0 • 编程工具:Wing IDE • Python版本:2.7.9 • 涉及 ...
- Entity Framework 5.0系列之Code First数据库迁移
我们知道无论是"Database First"还是"Model First"当模型发生改变了都可以通过Visual Studio设计视图进行更新,那么对于Cod ...
- JavaScript工具库之Lodash
你还在为JavaScript中的数据转换.匹配.查找等烦恼吗?一堆看似简单的foreach,却冗长无趣,可仍还在不停的repeat it!也许你已经用上了Underscore.js,不错,你已经进步很 ...
- Unity 热更新实例一、C#Light 和UI系统使用实例
接下来我会运用热更新的机制,逐步制作一些例子来阐释脚本系统如何和Unity结合. 脚本不限于使用C#Lite,但是C#Lite会有一些便利之处,请往下看. 结合机制也不限于这一种,但是C#Lite的设 ...