CSS3 动画


@keyframes:定义一个动画
animation:在HTML元素上应用动画

animation-name动画名称
animation-duration动画持续时间
animation-timing-function动画速度曲线
animation-delay动画开始的时间,延迟
animation-iteration-count动画播放次数,默认为1
animation-direction动画在下一个是否逆向播放,默认为normal,逆向为alternate
animation-fill-mode规定对象动画时间之外的状态

使一个div从一个位置移动到另一个位置并变换背景颜色

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>

        .div1{
            width: 200px;
            height: 200px;
            background-color: black;
            position: absolute;
            top: 100px;
            left: 100px;
            animation-name: myframe;
            animation-duration: 2s;
        }
        @keyframes myframe {
            from{
                top: 100px;
                left: 100px;
                background-color: black;
            }to{
                top: 400px;
                left: 400px;
                background-color: mediumspringgreen;
                         }
        }

    </style>
</head>
<body>
        <div class="div1"></div>
</body>
</html>

使一个div平移一圈

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>

        .div1{
            width: 200px;
            height: 200px;
            background-color: black;
            animation-name: myframe;
            animation-duration: 2s;
            animation-iteration-count:infinite;
        }
        @keyframes myframe {
           0%{

           }
            25%{
                margin-left: 400px;
                margin-top: 0;
            }
            50%{
                margin-left: 400px;
                margin-top: 400px;
            }
            75%{
                margin-top: 400px;
                margin-left: 0;
            }
            100%{
                margin-top: 0;
                margin-left: 0;
            }
        }

    </style>
</head>
<body>
        <div class="div1"></div>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值