animation:动画

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>回忆录</title>
  <link rel="stylesheet" href="./index.css">
</head>

<body>
  <div></div>
</body>
<script>
</script>

</html>
* {
    margin: 0;
    padding: 0;
}

div {
    width: 100px;
    height: 100px;
    background-color: #6666FF;
    position: absolute;
    /* animation: run 3s, color-change 3s; */
    /*注意:可以将多个关键帧写在一起*/
    animation: run 3s ease-in 1s 1 normal both;
    /*
    第一个值run:代表动画的名称
    第二个值3s:代表执行完动画需要花费多久的时间
    第三个值ease-in:代表运动的速度(每一段的)(默认值==ease:平滑过渡)
    第四个值1s:代表运动前延迟的时间(默认值==0)
    第五个值1:代表运动几次(infinite:无线循环)
    第六个值normal:代表运动方向(默认值==normal)
    第七个值backwards:代表运动的状态
        (默认值==none,
        backwards运动开始前的状态为#6666FF,结束后也为#6666FF)
        forwards运动结束前最后一帧的状态为#ff0000,结束后也为#ff0000)
    */
}

div:hover {
    animation-play-state: paused;
    /*停止运动:兼容性不好,不推荐使用*/
}

@keyframes run {
    0% {
        /*注意:0% == from */
        left: 0;
        top: 0;
        background-color: #ff0000;
    }
    25% {
        left: 200px;
        top: 0;
        background-color: #ff0000;
    }
    50% {
        left: 200px;
        top: 200px;
        background-color: #ff0000;
    }
    75% {
        left: 0;
        top: 200px;
        background-color: #ff0000;
    }
    100% {
        /* 100% == to */
        left: 0;
        top: 0;
        background-color: #ff0000;
    }
}

/*
举例子:0% == from 100% == to ,run与run1效果一样的。
    @keyframes run1{
        from{ 
            left: 0;
            top: 0;
        }
        25%{
            left: 200px;
            top:0;
        }
        50%{
            left: 200px;
            top:200px;
        }
        75%{
            left: 0;
            top:200px;
        }
        to{ 
            left: 0;
            top:0;
        }
    }
*/

/*一边移动一边改变颜色:*/

@keyframes color-change {
    from {
        /* left: 0;
        top: 0; */
        background-color: #ff0000;
    }
    25% {
        /* left: 200px;
        top:0; */
        background-color: #FFFF00;
    }
    50% {
        /* left: 200px;
        top:200px; */
        background-color: #0000ff;
    }
    75% {
        /* left: 0;
        top:200px; */
        background-color: #00FF00;
    }
    to {
        /* left: 0;
        top:0; */
        background-color: #000000;
    }
}

/*
    关键帧存在兼容性问题,为了解决这个问题,
    是使用关键帧时一定要加进行兼容性处理。
    @keyframes run {
        0% {
            left: 0;
            top: 0;
        }
        25% {
            left: 200px;
            top: 0;
        }
        50% {
            left: 200px;
            top: 200px;
        }
        75% {
            left: 0;
            top: 200px;
        }
        100% {
            left: 0;
            top: 0;
        }
    }

     @-webkit-keyframes run {
        0% {
            left: 0;
            top: 0;
        }
        25% {
            left: 200px;
            top: 0;
        }
        50% {
            left: 200px;
            top: 200px;
        }
        75% {
            left: 0;
            top: 200px;
        }
        100% {
            left: 0;
            top: 0;
        }
    }

     @-moz-keyframes run {
        0% {
            left: 0;
            top: 0;
        }
        25% {
            left: 200px;
            top: 0;
        }
        50% {
            left: 200px;
            top: 200px;
        }
        75% {
            left: 0;
            top: 200px;
        }
        100% {
            left: 0;
            top: 0;
        }
    }
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值