CSS3 animation-fill-mode 属性 | CSS3教程:CSS3动画

返回到:CSS3动画 | CSS3教程

定义和用法

animation-fill-mode 属性规定当动画不播放时(当动画完成时,或当动画有一个延迟未开始播放时),要应用到元素的样式。

默认情况下,CSS 动画在第一个关键帧播放完之前不会影响元素,在最后一个关键帧完成后停止影响元素。animation-fill-mode 属性可重写该行为。

默认值:none
继承:
可动画化:否。
版本:CSS3
JavaScript 语法:object.style.animationFillMode=”forwards”

CSS 语法

animation-fill-mode: none|forwards|backwards|both|initial|inherit;

属性值

描述
none默认值。动画在动画执行之前和之后不会应用任何样式到目标元素。
forwards在动画结束后(由 animation-iteration-count 决定),动画将应用该属性值。
backwards动画将应用在 animation-delay 定义期间启动动画的第一次迭代的关键帧中定义的属性值。这些都是 from 关键帧中的值(当 animation-direction 为 “normal” 或 “alternate” 时)或 to 关键帧中的值(当 animation-direction 为 “reverse” 或 “alternate-reverse” 时)。
both动画遵循 forwards 和 backwards 的规则。也就是说,动画会在两个方向上扩展动画属性。
initial设置该属性为它的默认值。
inherit从父元素继承该属性。

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

紧跟在 -webkit-, -ms- 或 -moz- 前的数字为支持该前缀属性的第一个浏览器版本号。

属性谷歌IE火狐苹果opera
animation-fill-mode4.0 -webkit-10.016.0
5.0 -moz-
4.0 -webkit-15.0 -webkit-
12.1
12.0 -o-

实例

把物体动画地从一个地方移动到另一个地方,并让它停留在那里:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Web176教程网(web176.com)</title> 
<style> 
div
{
	width:100px;
	height:100px;
	background:red;
	position:relative;
	animation:mymove 3s;
	animation-iteration-count:2;
	animation-fill-mode:forwards;

	/* Safari 和 Chrome */
	-webkit-animation:mymove 3s;
	-webkit-animation-iteration-count:2;
	-webkit-animation-fill-mode:forwards;
}

@keyframes mymove
{
	from {top:0px;}
	to {top:200px;}
}

@-webkit-keyframes mymove /* Safari 和 Chrome */
{
	from {top:0px;}
	to {top:200px;}
}
</style>
</head>
<body>

<p><strong>注意:</strong>Internet Explorer 9 及其之前的版本不支持 animation-fill-mode 属性。</p>

<div></div>

</body>
</html>

作者:terry,如若转载,请注明出处:https://www.web176.com/css3animate/5060.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2022年1月10日 下午2:53
下一篇 2022年1月10日 下午2:59

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注