css3动画:奔跑的北极熊

css3动画:奔跑的北极熊

编辑器:vs code 效果

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>冰山</title>
    <style>
        body {
            background-color: #333;
            background: url(./img/夜晚.jpg);
            /* background-size: 100%; */
            /* z-index: -1; */
        }

        .ice {
            top: 50%;
            position: absolute;
            width: 3840px;
            height: 336px;
            background: url(./img/bg1.png);
            animation: s 15s linear infinite;
        }

        @keyframes s {
            0% {
                background-position: 0 0;
            }

            100% {
                /* left: 50%;
                transform: translateX(-50%); */
                background-position: -1600px 0;
            }
        }

        .bears {
            top: 82%;
            position: absolute;
            width: 200px;
            height: 100px;
            background: url(./img/bear.png) no-repeat;
            animation: bear 0.7s infinite steps(8), move 3s forwards
        }

        @keyframes bear {
            0% {
                background-position: 0 0;
            }

            100% {
                /* left: 50%;
                transform: translateX(-50%); */
                background-position: -1600px 0;
            }

        }

        @keyframes move {
            0% {
                left: 0;
            }

            100% {
                left: 50%;
                transform: translateX(-50%);
            }
        }
    </style>
</head>

<body>
    <div class="icbear">
        <div class="ice">

        </div>
        <div class="bears">

        </div>
    </div>

</body>

</html>
经验分享 程序员 微信小程序 职场和发展