前言:
好久没写文章了,今天看到webQQ又一次升级。我用的chrome的画面切换甚至用到了css 3d animation+3dtransform。
本系列文章用于介绍如何仅用css实现3d动画,这是本系列的第一篇文章,仅仅只介绍了动画。也许这篇文章也许过于超前,因为大部分的浏览器器,甚至包括FF,都还没有实现3d transform。涉及到animation的部分,你可以通过webkit内核的浏览器(Chrome or Safari)或者Firefox来浏览,但是涉及到3d transform的东西请用webkit的浏览器器浏览。
Css3 @KeyFrames Rule
什么是KeyFrames?直译过来就是关键帧。你可以把他理解为flash中的关键帧。他以关键字from开始,to结束。中间的部分都为百分比。意为动画到了某个百分比时,他的状态。而帧与帧之间的补间动画浏览器会帮你自动生成。
例如:
<style type="text/css">
@keyframes myfirst {
from {background: red;}
to {background: yellow;}
}
@-moz-keyframes myfirst /* Firefox */ {
from {background: red;}
to {background: yellow;}
}
@-webkit-keyframes myfirst /* Safari and Chrome */ {
from {background: red;}
to {background: yellow;}
}
</style>
为了支持将来可能有的标准,你不得不写3遍。
试着运行下面的代码,里面可能会有你没见过的属性,我们下面会讲到
大家等待了两秒后,突然从画面左上角出现一个方块,花费5秒从红色变到黄色。可能大家已经猜到了
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
@keyframes myfirst {
from {background: red;}
to {background: yellow;}
}
@-moz-keyframes myfirst /* Firefox */ {
from {background: red;}
to {background: yellow;}
}
@-webkit-keyframes myfirst /* Safari and Chrome */ {
from {background: red;}
to {background: yellow;}
}
#sample {
animation-name: myfirst;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-play-state: running;
/* Firefox: */
-moz-animation-name: myfirst;
-moz-animation-duration: 5s;
-moz-animation-timing-function: linear;
-moz-animation-delay: 2s;
-moz-animation-iteration-count: infinite;
-moz-animation-direction: alternate;
-moz-animation-play-state: running;
/* Safari and Chrome: */
-webkit-animation-name: myfirst;
-webkit-animation-duration: 5s;
-webkit-animation-timing-function: linear;
-webkit-animation-delay: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
-webkit-animation-play-state: running;
}
</style>
</head>
<body>
<div id="sample" style="width:120px; height:120px;">
</div>
</body>
</html>
animation-name: 和上面的@keyframe的名字对应起来,代表当前用的是何种变换
animation-duration: 代表动画开始到结束总共耗时多少时间
animation-timing-function: 代表动画的进行是均匀的还是先快后慢还是?他有这几个枚举值:linear:线性,ease:默认值,先慢后快,到了快一半的时候再变慢,ease-in:先慢后快,ease-out:先快后慢。ease-in-out:两头慢,中间快。cubic-bezier(n,n,n,n):自定义,n只能输入0-1之间的值。输入的值越大,移动的越慢,4个n代表了动画的4个阶段25%,50%,75%,100%。
也就是说,linear,ease等值,只是cubic-bezier在浏览器中的预设值,可以简单表示如下:
#linear {animation-timing-function: cubic-bezier(0,0,1,1;}
#ease {animation-timing-function: cubic-bezier(0.25,0.1,0.25,1);}
#ease-in {animation-timing-function: cubic-bezier(0.42,0,1,1);}
#ease-out {animation-timing-function: cubic-bezier(0,0,0.58,1);}
#ease-in-out {animation-timing-function: cubic-bezier(0.42,0,0.58,1);}
animation-delay:代表动画延迟多少时间开始,默认为0
animation-iteration-count:代表动画执行多少次,默认为1.如果输入infinite,则代表无限次
animation-direction:默认值为normal,代表动画执行完后从头开始。如果设置为alternate,那么动画在结束后,第二遍会反着执行一遍
animation-play-state:默认值running,代表现在是执行状态。如果要让动画停止,只需要把这个值赋值为paused
好,接下来把上面的代码串联起来。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
@keyframes myfirst {
from {left:0px; top:0px; background: red; }
50% {left:100px; top:80px;}
70%, 80% {transform: rotate(-360deg);left:240px; top:240px;}
to {left:279px; top:279px; background: yellow;}
}
@-moz-keyframes myfirst /* Firefox */ {
from {left:0px; top:0px; background: red; }
50% {left:100px; top:80px;}
70%, 80% {-moz-transform: rotate(-360deg);left:240px; top:240px;}
to {left:279px; top:279px; background: yellow;}
}
@-webkit-keyframes myfirst /* Safari and Chrome */ {
from {left:0px; top:0px; background: red; }
50% {left:100px; top:80px;}
70%, 80% {-webkit-transform: rotate(-360deg) scale(0.5, 0.5);left:240px; top:240px;}
to {left:279px; top:279px; background: yellow;}
}
#sample {
animation-name: myfirst;
animation-duration: 5s;
animation-timing-function: linear;
animation-iteration-count: infinite;
animation-direction: alternate;
/* Firefox: */
-moz-animation-name: myfirst;
-moz-animation-duration: 5s;
-moz-animation-timing-function: linear;
-moz-animation-iteration-count: infinite;
-moz-animation-direction: alternate;
/* Safari and Chrome: */
-webkit-animation-name: myfirst;
-webkit-animation-duration: 5s;
-webkit-animation-timing-function: linear;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: alternate;
}
</style>
</head>
<body>
<div style="width:400px; height:400px; border-style:dashed; border-width:1px; position:relative;">
<div id="sample" style="width:120px; height:120px; position:absolute;"></div>
</div>
</body>
</html>
上面的sample可以参考附件。以上就是css-animation标准的全部内容上面的sample可以参考附件。
分享到:
相关推荐
在CSS3中,`animation`属性是一个强大的工具,它允许我们创建复杂的动态效果,比如我们的主题——3D弹力球的弹跳动画。这个动画效果不仅增强了用户界面的视觉吸引力,还能提供更好的交互体验。接下来,我们将深入...
本项目“纯css3-球形3d旋转-多图3d球形旋转”着重展示了如何利用CSS3的特性来实现一个动态的、三维球形的图像旋转展示效果。这种效果可以用于网站的轮播图、产品展示或任何需要吸引用户注意力的地方。 首先,我们来...
在Web上实现动画,主要依靠CSS3的两个关键特性:过渡(Transitions)和动画(Animations)。过渡用于平滑地改变一个元素从一种样式到另一种样式的状态,而动画则更加强大,可以控制整个过程的时间线和关键帧,实现更...
【纯CSS3 3D旋转科技球体动画特效】是一种利用现代浏览器支持的CSS3特性实现的视觉效果,它能够创建出引人入胜、富有动态感的科技风格球体旋转展示。在网页设计和开发中,这样的特效可以增强用户体验,使网站或应用...
通过CSS3中的animation-iteration-count属性来实现爱心效果
本项目"css3-3d旋转-色子"就是对这一技术的生动运用,它通过CSS3实现了一个3D旋转的色子动画,用户可以自由定制布局和动画频次,适应不同的应用场景。 ### CSS3 3D变换基础 CSS3的3D变换主要由以下几种属性组成: ...
之前我们分享过一些基于CSS3和SVG的自行车动画,比如这款SVG/CSS3自行车 模拟自行车行驶动画和纯CSS3 3D自行车动画都非常炫酷。今天我们要给大家介绍另外一款基于SVG的3D镂空自行车骑行动画,与前面自行车动画不同的...
CSS3作为CSS的最新版本,引入了许多新的特性和功能,其中之一就是3D效果的实现。本篇文章将详细探讨如何使用CSS3来创建具有3D光泽效果的文字,以"css3-3d-shine-text.zip"中的实例为引导,帮助你理解和掌握这一技巧...
3. **CSS3 动画**:CSS3的`transition`和`animation`属性使得我们可以平滑地过渡到不同的样式状态,创造出流畅的动画效果。在图片轮播中,这些属性用于控制图片在切换时的速度和效果,如淡入淡出、滑动进出等。 4. ...
同时,CSS3的3D变换使得小球具有立体感,落地和跳动的效果通过关键帧动画实现,呈现出逼真的物理运动规律。 具体到CSS3的3D变换,主要涉及以下几个属性: 1. `transform`:这个属性允许我们对元素进行旋转、缩放、...
CSS3的Animation属性是现代网页设计中的一个重要工具,它使得开发者能够创建复杂的动态效果,如平滑的过渡、动画序列等,而无需依赖JavaScript或者其他外部库。在本案例中,我们将深入探讨如何使用CSS3的animation...
而CSS3的animation属性则是实现动态视觉效果的关键。它包括`animation-name`、`animation-duration`、`animation-timing-function`、`animation-delay`、`animation-iteration-count`、`animation-direction`、`...
在现代网页设计中,CSS3 Animation(动画)是一个不可或缺的元素,它使得网页元素能够动态地改变其样式,创造出引人入胜的视觉效果。本篇文章将深入探讨CSS3动画的基本概念、语法以及常见应用场景,帮助你更好地理解...
【标题】"CSS3 3D立方体菜单"是一个基于CSS3技术实现的创新交互式菜单设计。在网页设计中,这种3D效果为用户界面带来了动态和立体感,提升了用户体验。通过使用CSS3的变换(transform)和透视(perspective)属性,...
通过以上知识点的应用,"css3 3D邮寄信封打开动画特效"可以实现一个引人入胜的用户体验,增加网站的互动性和趣味性。在实际项目中,开发者需要结合具体需求和用户群体,恰当地运用这些技术,打造既美观又实用的网页...
**CSS3 Animation动画详解** CSS3是Web设计领域的一个重大突破,它引入了许多新的特性,其中最引人注目的就是动画(Animation)功能。通过CSS3的动画,开发者可以为网页元素添加平滑、动态的效果,提升用户体验。在...
【CSS3实现3D人物走路动画特效】 在现代网页设计中,动态效果是吸引用户注意力、提升用户体验的重要手段。CSS3作为 Cascading Style Sheets 的最新版本,提供了丰富的样式控制和强大的动画功能,使得无需依赖...
在"css3-3d-svg-button.zip"文件中,包含的就是这样一个实例,通过CSS3和SVG的巧妙结合,实现了一个具有3D效果且背景为SVG动画的按钮。实现这样的效果主要分为以下几个步骤: 1. **SVG图形创建**:首先,我们需要...
CSS3是层叠样式表(Cascading Style Sheets)的第三版,它引入了许多新特性和功能,极大地扩展了网页设计的可能性,包括动画和特效。烟花特效就是其中的一种,它可以为网页增添节日氛围或者为用户界面带来独特的视觉...
在本文中,我们将深入探讨如何使用CSS3 Animation创建酷炫的文字动画特效。CSS3 Animation是现代网页设计中不可或缺的一部分,它允许我们为元素添加平滑、动态的效果,从而提升用户体验和视觉吸引力。在这个主题中,...