其他分享
首页 > 其他分享> > CSS:吃豆子动画

CSS:吃豆子动画

作者:互联网

主要用到了CSS3动画以及CSS3 转换。

代码如下:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            margin: 50px 50px;
            position: relative;
            width: 350px;
            height: 200px;
        }
        .head {
            position: relative;
            width: 200px;
            height: 200px;
            background-color: white;
            border-radius: 50%;
            overflow: hidden;
        }
        .head::before,
        .head::after {
            position: absolute;
            z-index: 1;
            left: 0;
            content: '';
            width: 200px;
            height: 100px;
            background-color: orangered;
        }
        .head::before {
            top: 0;
            transform-origin: 100px 100px;
            animation: top .5s linear infinite alternate;
        }
        .head::after {
            top: 100px;
            transform-origin: 100px 0px;
            animation: bottom .5s linear infinite alternate ;
        }
        .dot {
            position: absolute;
            left: 100px;
            top: 50%;
            transform: translateY(-50%);
            width: 15px;
            height: 15px;
            border-radius: 50%;
            background-color: red;
            box-shadow: 50px 0 0 orange, 100px 0 0 orange, 150px 0 0 orange,200px 0 0 orange;
            animation: eat .5s linear infinite;
        }
        @keyframes top {
            0% {
                transform: rotate(-30deg);
            }
            100% {
                transform: rotate(0deg);
            }
        }
        @keyframes bottom {
            0% {
                transform: rotate(30deg);
            }
            100% {
                transform: rotate(0deg);
            }
        }
        @keyframes eat {
            100% {
                left: 0;
            }
        }
    </style>
</head>
<body>
        <div class="box">
            <div class="head"></div>
            <div class="dot"></div>
        </div>
</body>
</html>

效果图:

标签:豆子,动画,head,top,100px,transform,height,CSS,200px
来源: https://blog.csdn.net/m0_57835615/article/details/117519622