CSS3学習---アニメーション

声明:以下の内容は個人的な研究の要約であり、本来の意図は彼ら自身の研究とレビュー記録を促進することです。間違いがあれば訂正してください!

アニメーションの使い方

  1. アニメーションを定義する
  2. 転送

ケース1:バルーンを円を描くように回転させる

ここに画像の説明を挿入
実装コード:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        img {
     
     
            width: 100px;
            /* 调用动画 */
            animation-name: move;
            /* 动画持续时间 */
            animation-duration: 10s;
            /*动画被播放次数,默认是1(infinite表示无限次)  */
            animation-iteration-count: infinite;
        }
        /* 动画的定义 */
        @keyframes move {
     
     
            /* 开始 */
            0% {
     
     
                transform: translate(0px, 0px);
            }
            25% {
     
     
                transform: translate(1000px, 0px);
            }
            50% {
     
     
                transform: translate(1000px, 500px);
            }
            75% {
     
     
                transform: translate(0px, 500px);
            }
            /* 结束 */
            100% {
     
     
                transform: translate(0px, 0px);
            }
        }
    </style>
</head>
<body>
    <div>
        <img src="imgs/hop.png" alt="">
    </div>
</body>
</html>

ケース2:ランニングベア

ここに画像の説明を挿入
実装コード:

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
     
     
            background-color: #ccc;
        }
        
        .bear {
     
     
            position: absolute;
            width: 200px;
            height: 100px;
            background: url(imgs/bear.png) no-repeat;
            /* 动画1bear:图片长度是1600px,共8个动作,所以盒子宽度设为200px,分8步动画实现熊走动;
            动画2move:移动到屏幕中央,保持位置 */
            animation: bear 5s steps(8) infinite, move 5s forwards;
        }
        
        @keyframes bear {
     
     
            0% {
     
     
                background-position: 0 0;
            }
            100% {
     
     
                background-position: -1600px 0;
            }
        }
        
        @keyframes move {
     
     
            0% {
     
     
                bottom: 10px;
                left: 0px;
            }
            100% {
     
     
                bottom: 10px;
                left: 50%;
                transform: translateX(-50%);
            }
        }
    </style>
</head>

<body>

    <div class="bear">

    </div>


</body>

</html>

おすすめ

転載: blog.csdn.net/pilgrim_121/article/details/111402156