CSS3中的动画功能

1.transitions功能

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
    div{
        margin-top:150px;
        background-color:#ffff00;
        color:#000;
        width:100px;
        transition:transform,background-color 1s linear,color 1s linear,width 1s linear;
    }
    div:hover{
        background-color:#f0f;
        transform:rotate(45deg);
        color:#fff;
        width:200px;
    }
</style>
</head>

<body>

    <div>transition Demo</div>

</body>
</html>

这里写图片描述

2.animations功能

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
    div{
        background-color:red;
    }
    @-webkit-keyframes mycolor {
        /* 开始帧 */
        0%{
            background-color:red;
        }
        /* 背景颜色变化帧-黄色 */
        40%{
            background-color:#ff0;
        }
        /* 背景颜色变化帧-蓝色 */
        70%{
            background-color:aqua;
        }
        /* 结束帧 */
        100%{
            background-color:red;
        }
    }
    div:hover{
        -webkit-animation:mycolor 5s linear;
    }
</style>
</head>

<body>

    <div>示例文字</div>

</body>
</html>

3.实现多个属性值同时改变的动画

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
    div{
        position:absolute;
        background-color:#ff0;
        top:100px;
        width:500px;
    }
    @-webkit-keyframes mycolor {
        0%{
            background-color:red;
            transform:rotate(0deg);
        }
        30%{
            background-color:aqua;
            transform:rotate(30deg);
        }
        60%{
            background-color:lightskyblue;
            transform:rotate(-30deg);
        }
        100%{
            background-color:red;
            transform:rotate(0deg);
        }
    }
    div:hover{
        -webkit-animation-name:mycolor;
        -webkit-animation-duration:5s;
        -webkit-animation-timing-function:linear;
    }
</style>
</head>

<body>

    <div>示例文字</div>

</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值