css3动画如何在动作结束时保持该状态不变

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

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

实例(添加下面属性到类名里面)

把物体动画地从一个地方移动到另一个地方,并让它停留在那里:
animation-fill-mode:forwards;
-webkit-animation-fill-mode:forwards; /* Safari 和 Chrome */


<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.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>

你可能感兴趣的:(css运用,css动画)