Day32动画--animation属性

animation复合属性
image

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>animation属性</title>
    <style>
        .box{
            width: 200px;
            height: 100px;
            background-color: pink;
            /* linear:匀速 */
            animation: change 2s linear;
            /* steps:分步动画,实际应用中配合精灵图实现精灵动画 */
            animation: change 2s steps(3);

            /* 如果有两个时间,第一个是动画时长,第二个是延迟时间  若是没有s的单位,则是动画的播放次数*/
            animation: change 2s 3s;
            animation: change 2s 3;

            /* 重复次数,infinite:无限循环 */
            animation: change 2s infinite;
            /* alternate:反向 */
            animation: change 2s infinite alternate; 

            /* 动画执行完毕的状态:forward:结束状态:backward:开始状态(默认) */
            animation: change 2s forwards;
            animation: change 2s backwards;
        }
        /* 宽度从200变化到800 */ 
        @keyframes change {
            from{
                width: 200px;
            }
            to{
                width: 800px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>

animation单独属性
image

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>animation拆分写法</title>
    <style>
        .box{
            width: 200px;
            height: 100px;
            background-color: pink;
            animation-name: change;
            animation-duration: 1s;
            animation-iteration-count: infinite;
        }
        .box:hover{
            animation-play-state: paused;
        }
        /* 宽度从200变化到800 */
        @keyframes change {
            from{
                width: 200px;
            }
            to{
                width: 800px;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
</body>
</html>
posted @ 2025-12-16 15:55  冰涿  阅读(5)  评论(0)    收藏  举报