HTML5基础加强css样式篇(animation填充属性:animation-fill-mode,播放控制属性:animation-play-state,播放顺序设置,)(三十一)

1.animation-fill-mode属性简介:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            /* .box 默认样式 */
            margin: 200px 0 0 200px;
            width: 200px;
            height: 200px;
            background-color: deeppink;
            animation-name: anim1;
            animation-duration: 3s;
            animation-delay: 2s;
            /*在动画未播放时,显示动画第一帧*/
            animation-fill-mode: backwards;
            /*在动画播放完,显示动画最后一帧*/
            animation-fill-mode: forwards;
            /*向前和向后填充模式都被应用。*/
            animation-fill-mode: both;
        }
        @keyframes anim1 {

            0%{
                background-color: red;
            }
            50%{
                background-color:  blue;
            }
            100%{
                background-color:  green;
            }

        }
    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>


2.animation-play-state 属性简介:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            /* .box 默认样式 */
            margin: 200px 0 0 200px;
            width: 200px;
            height: 200px;
            /*background-color: orange;*/
            animation-name: anim2;
            /*animation-delay: 1s;*/
            animation-duration: 3s;
            animation-fill-mode: both;

            /*控制动画的次数*/
            animation-iteration-count: 2;
            /*控制动画的次数 infinite --- 无限次的播放 */
            animation-iteration-count: infinite;

        }
        /*当鼠标悬浮在.box时,暂停播放动画*/
        .box:hover {
            animation-play-state: paused;
        }

        @keyframes anim2 {
            10%{
                background: url("img/1.png") no-repeat;
                background-size: 100%;
            }
            50%{
                background: url("img/2.png") no-repeat;
                background-size: 100%;
            }
           80%{
                background: url("img/3.png") no-repeat;
                background-size: 100%;
            }
        }

    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>

3,播放顺序设置:animation-direction :reverse,alternate, 播放次数:animation-iteration-count:infinite

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            /* .box 默认样式 */
            margin: 200px 0 0 200px;
            width: 200px;
            height: 200px;
            /*background-color: orange;*/
            animation-name: anim2;
            /*animation-delay: 1s;*/
            animation-duration: 3s;
            animation-fill-mode: both;

            /*控制动画的次数*/
            animation-iteration-count: 2;
            /*控制动画的次数 infinite --- 无限次的播放 */
            /*animation-iteration-count: infinite;*/

            /*控制每一帧的播放顺序 reverse - 反向播放*/
            animation-direction: reverse;
            /*控制每一帧的播放顺序 alternate - 交替反复播放,必须配合播放次数使用,播放次数大于1*/
            animation-direction: alternate;

        }
        /*当鼠标悬浮在.box时,暂停播放动画*/
        .box:hover {
            animation-play-state: paused;
        }

        @keyframes anim2 {
            10%{
                background: url("img/1.png") no-repeat;
                background-size: 100%;
            }
            50%{
                background: url("img/2.png") no-repeat;
                background-size: 100%;
            }
           80%{
                background: url("img/3.png") no-repeat;
                background-size: 100%;
            }
        }

    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>

4,综合使用:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        .box {
            /* .box 默认样式 */
            margin: 200px 0 0 200px;
            width: 200px;
            height: 200px;
            background-color: orange;
            animation-name: anim2;
            animation-delay: 2s;
            animation-duration: 3s;
            animation-fill-mode: both;

            /*animation-fill-mode: backwards;*/

            /*控制动画的次数*/
            /*animation-iteration-count: 2;*/
            /*控制动画的次数 infinite --- 无限次的播放 */
            animation-iteration-count: infinite;

            /*控制每一帧的播放顺序 reverse - 反向播放*/
            animation-direction: reverse;
            /*如果反向播放,第一帧是 100%{}, 最后一帧 0%{}*/

        }
        /*当鼠标悬浮在.box时,暂停播放动画*/
        .box:hover {
            animation-play-state: paused;
        }

        @keyframes anim2 {
            0%{
                background: url("img/1.png") no-repeat;
                background-size: 100%;
            }
            50%{
                background: url("img/2.png") no-repeat;
                background-size: 100%;
            }
            100%{
                background: url("img/3.png") no-repeat;
                background-size: 100%;
            }
        }

    </style>
</head>
<body>

<div class="box"></div>

<script type="text/javascript">
</script>
</body>
</html>



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

咸鸭蛋炒饭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值