css动画属性,CSS动画
大家好,关于css动画属性很多朋友都还不太明白,今天小编就来为大家分享关于CSS动画的知识,希望对各位有所帮助!
css3里面动画有没有用过动画的属性有哪些具体是什么
CSS3动画属性
下面的表格列出了@keyframes规则和所有动画属性:
@keyframes规定动画。
animation所有动画属性的简写属性,除了 animation-play-state属性。
animation-name规定@keyframes动画的名称。
animation-duration规定动画完成一个周期所花费的秒或毫秒。默认是 0。 3
animation-timing-function规定动画的速度曲线。默认是"ease"。 3
animation-delay规定动画何时开始。默认是 0。 3
animation-iteration-count规定动画被播放的次数。默认是 1。
animation-direction规定动画是否在下一周期逆向地播放。默认是"normal"。
animation-play-state规定动画是否正在运行或暂停。默认是"running"。
animation-fill-mode规定对象动画时间之外的状态。
下面的两个例子设置了所有动画属性:
实例
运行名为 myfirst的动画,其中设置了所有动画属性:
div
{
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和 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;
/* Opera:*/
-o-animation-name: myfirst;
-o-animation-duration: 5s;
-o-animation-timing-function: linear;
-o-animation-delay: 2s;
-o-animation-iteration-count: infinite;
-o-animation-direction: alternate;
-o-animation-play-state: running;
}
css动画用什么规则
想要创建CSS3动画就需要使用到@keyframes规则和animation属性;其中@keyframes规则是创建动画,它指定一个CSS样式和动画将逐步从目前的样式更改为新的样式。
CSS3动画是什么?
动画是使元素从一种样式逐渐变化为另一种样式的效果。使用@keyframes规则,你可以创建动画。
当在@keyframes创建动画,把它绑定到一个选择器,否则动画不会有任何效果。
指定至少这两个CSS3的动画属性绑定向一个选择器:
●规定动画的名称
●规定动画的时长
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
紧跟在-webkit-,-ms-或-moz-前的数字为支持该前缀属性的第一个浏览器版本号。
@keyframes规则
语法
@keyframes animationname{keyframes-selector{css-styles;}}属性值:
●animationname必需的。定义animation的名称。
●keyframes-selector必需的。动画持续时间的百分比。
合法值:
●0-100%
●from(和0%相同)
●to(和100%相同)
●css-styles必需的。一个或多个合法的CSS样式属性
说明:
您可以改变任意多的样式任意多的次数。
请用百分比来规定变化发生的时间,或用关键词"from"和"to",等同于 0%和 100%。
0%是动画的开始,100%是动画的完成。
为了得到最佳的浏览器支持,您应该始终定义 0%和 100%选择器。
css动画示例
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;
animation:mymove 5s infinite;
-webkit-animation:mymove 5s infinite;/* Safari and Chrome*/
}
@keyframes mymove
{
0%{top:0px; left:0px; background:red;}
25%{top:0px; left:100px; background:blue;}
50%{top:100px; left:100px; background:yellow;}
75%{top:100px; left:0px; background:green;}
100%{top:0px; left:0px; background:red;}
}
@-webkit-keyframes mymove/* Safari and Chrome*/
{
0%{top:0px; left:0px; background:red;}
25%{top:0px; left:100px; background:blue;}
50%{top:100px; left:100px; background:yellow;}
75%{top:100px; left:0px; background:green;}
100%{top:0px; left:0px; background:red;}
}
</style>
</head>
<body>
<div></div>
</body>
</html>效果图:
css3中怎样定义动画的旋转中心点
我们没有使用transform-origin改变元素原点位置的情况下,CSS变形进行的旋转、移位、缩放等操作都是以元素自己中心(变形原点)位置进行变形的。但很多时候需要在不同的位置对元素进行变形操作,我们就可以使用transform-origin来对元素进行原点位置改变,使元素原点不在元素的中心位置,以达到需要的原点位置。如果我们把元素变换原点(transform-origin)设置0(x) 0(y),这个时候元素的变换原点转换到元素的左顶角处。改变transform-origin属性的X轴和Y轴的值就可以重置元素变形原点位置,其基本语法如下所示:`transform-origin:[<percentage>|<length>| left| center| right| top| bottom]| [<percentage>|<length>| left| center| right]| [[<percentage>|<length>| left| center| right]&& [<percentage>|<length>| top| center| bottom]]<length>?`transform-origin属性值可以是百分比、em、px等具体的值,也可以是top、right、bottom、left和center这样的关键词。2D的变形中的transform-origin属性可以是一个参数值,也可以是两个参数值。如果是两个参数值时,第一值设置水平方向X轴的位置,第二个值是用来设置垂直方向Y轴的位置。3D的变形中的transform-origin属性还包括了Z轴的第三个值。其各个值的取值简单说明如下: x-offset:用来设置transform-origin水平方向X轴的偏移量,可以使用<length>和<percentage>值,同时也可以是正值(从中心点沿水平方向X轴向右偏移量),也可以是负值(从中心点沿水平方向X轴向左偏移量)。 offset-keyword:是top、right、bottom、left或center中的一个关键词,可以用来设置transform-origin的偏移量。 y-offset:用来设置transform-origin属性在垂直方向Y轴的偏移量,可以使用<length>和<percentage>值,同时可以是正值(从中心点沿垂直方向Y轴向下的偏移量),也可以是负值(从中心点沿垂直方向Y轴向上的偏移量)。 x-offset-keyword:是left、right或center中的一个关键词,可以用来设置transform-origin属性值在水平X轴的偏移量。 y-offset-keyword:是top、bottom或center中的一个关键词,可以用来设置transform-origin属性值在垂直方向Y轴的偏移量。 z-offset:用来设置3D变形中transform-origin远离用户眼睛视点的距离,默认值z=0,其取值可以<length>,不过<percentage>在这里将无效。
好了,本文到此结束,如果可以帮助到大家,还望关注本站哦!