纯CSS实现华为手机充电动画效果

162 阅读3分钟

用css实现华为充电动画的效果。这个动画涉及到了许多 CSS 和 HTML 的关键技术,包括 CSS 动画、定位、过滤器、伪元素、转换等。

废话不多说直接上代码

代码实现

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>华为充电动画</title>
    <style>
        htmlbody {
          width100%;
          height100%;
          display: flex;
          background#000;
          overflow: hidden;
        }
        .g-number {
          position: absolute;
          width300px;
          top27%;
          text-align: center;
          font-size32px;
          z-index10;
          color#fff;
        }
        .g-container {
          position: relative;
          width300px;
          height400px;
          margin: auto;
        }
        .g-contrast {
          filtercontrast(10hue-rotate(0);
          width300px;
          height400px;
          background-color#000;
          overflow: hidden;
          animation: hueRotate 10s infinite linear;
        }
        .g-circle {
          position: relative;
          width300px;
          height300px;
          box-sizing: border-box;
          filterblur(8px);
        }
        .g-circle::after {
          content"";
          position: absolute;
          top40%;
          left50%;
          transformtranslate(-50%, -50%rotate(0);
          width200px;
          height200px;
          background-color#00ff6f;
          border-radius42% 38% 62% 49% / 45%;
          animation: rotate 10s infinite linear;
        }
        .g-circle::before {
          content"";
          position: absolute;
          width176px;
          height176px;
          top40%;
          left50%;
          transformtranslate(-50%, -50%);
          border-radius50%;
          background-color#000;
          z-index10;
        }
        .g-bubbles {
          position: absolute;
          left50%;
          bottom0;
          width100px;
          height40px;
          transformtranslate(-50%0);
          border-radius100px 100px 0 0;
          background-color#00ff6f;
          filterblur(5px);
        }
        li {
          position: absolute;
          border-radius50%;
          background#00ff6f;
        }
        li:nth-child(0) {
          left22px;
          top50%;
          transformtranslate(-50%, -50%);
          width29px;
          height29px;
          animation: moveToTop 9s ease-in-out -0.158s infinite;
        }
        li:nth-child(1) {
          left85px;
          top50%;
          transformtranslate(-50%, -50%);
          width20px;
          height20px;
          animation: moveToTop 9s ease-in-out -4.128s infinite;
        }
        li:nth-child(2) {
          left36px;
          top50%;
          transformtranslate(-50%, -50%);
          width21px;
          height21px;
          animation: moveToTop 7s ease-in-out -2.829s infinite;
        }
        li:nth-child(3) {
          left35px;
          top50%;
          transformtranslate(-50%, -50%);
          width30px;
          height30px;
          animation: moveToTop 7s ease-in-out -2.35s infinite;
        }
        li:nth-child(4) {
          left70px;
          top50%;
          transformtranslate(-50%, -50%);
          width23px;
          height23px;
          animation: moveToTop 6s ease-in-out -3.211s infinite;
        }
        li:nth-child(5) {
          left36px;
          top50%;
          transformtranslate(-50%, -50%);
          width18px;
          height18px;
          animation: moveToTop 9s ease-in-out -1.44s infinite;
        }
        li:nth-child(6) {
          left52px;
          top50%;
          transformtranslate(-50%, -50%);
          width20px;
          height20px;
          animation: moveToTop 7s ease-in-out -2.99s infinite;
        }
        li:nth-child(7) {
          left37px;
          top50%;
          transformtranslate(-50%, -50%);
          width30px;
          height30px;
          animation: moveToTop 6s ease-in-out -4.638s infinite;
        }
        li:nth-child(8) {
          left52px;
          top50%;
          transformtranslate(-50%, -50%);
          width26px;
          height26px;
          animation: moveToTop 5s ease-in-out -0.428s infinite;
        }
        li:nth-child(9) {
          left73px;
          top50%;
          transformtranslate(-50%, -50%);
          width22px;
          height22px;
          animation: moveToTop 8s ease-in-out -0.278s infinite;
        }
        li:nth-child(10) {
          left33px;
          top50%;
          transformtranslate(-50%, -50%);
          width22px;
          height22px;
          animation: moveToTop 6s ease-in-out -2.439s infinite;
        }
        li:nth-child(11) {
          left16px;
          top50%;
          transformtranslate(-50%, -50%);
          width17px;
          height17px;
          animation: moveToTop 8s ease-in-out -2.508s infinite;
        }
        li:nth-child(12) {
          left36px;
          top50%;
          transformtranslate(-50%, -50%);
          width27px;
          height27px;
          animation: moveToTop 5s ease-in-out -2.181s infinite;
        }
        li:nth-child(13) {
          left43px;
          top50%;
          transformtranslate(-50%, -50%);
          width20px;
          height20px;
          animation: moveToTop 4s ease-in-out -1.748s infinite;
        }
        li:nth-child(14) {
          left20px;
          top50%;
          transformtranslate(-50%, -50%);
          width30px;
          height30px;
          animation: moveToTop 8s ease-in-out -3.665s infinite;
        }
        li:nth-child(15) {
          left16px;
          top50%;
          transformtranslate(-50%, -50%);
          width28px;
          height28px;
          animation: moveToTop 6s ease-in-out -3.521s infinite;
        }
        @keyframes rotate {
          50% {
            border-radius45% / 42% 38% 58% 49%;
          }
          100% {
            transformtranslate(-50%, -50%rotate(720deg);
          }
        }
        @keyframes moveToTop {
          90% {
            opacity1;
          }
          100% {
            opacity0.1;
            transformtranslate(-50%, -180px);
          }
        }
        @keyframes hueRotate {
          100% {
            filtercontrast(15hue-rotate(360deg);
          }
        }

    </style>
</head>
<body>
    <div>
        <div>98.7%</div>
        <div>
            <div></div>
            <ul>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>
        </div>
    </div>
</body>
</html>

最终效果

css实现华为充电动画