zoukankan      html  css  js  c++  java
  • 52.纯 CSS 创作一个小球绕着圆环盘旋的动画

    原文地址:https://segmentfault.com/a/1190000015295466

    感想:重点在小球绕环转动。

    HTML code:

    <div class="container">
        <div class="ring"></div>
        <div class="spheres">
            <span class="sphere"></span>
            <span class="sphere"></span>
            <span class="sphere"></span>
        </div>
    </div>

    CSS code:

    html, body {
        margin: 0;
        padding: 0;
    }
    body {
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: darkslategray;
    }
    /* 改变盒模型 为元素设定的宽度和高度包括了外内外边距 */
    *{
        box-sizing: border-box;
    }
    /* 画出圆环 */
    .container{
        position: relative;
        font-size: 20px;
        /* 最后,让容器转动起来,制造小球围绕圆环盘旋的效果 */
        animation: rotate 5s linear infinite;
    }
    .ring{
        position: relative;
        width: 10em;
        height: 10em;
        border: 1.5em solid paleturquoise;
        border-radius: 50%;
        z-index: 2;
    }
    /* 在圆环的左上方画出一个小球 */
    .sphere{
        position: absolute;
        top: -20%;
        left: -20%;
        /* 让小球盘旋 */
        width: 80%;
        height: 80%;
        animation: 
            rotate 1.5s linear infinite,
            overlapping 1.5s linear infinite;
    }
    /* 通过设置动画延时,制造 3 个小球同时盘旋的效果 */
    .sphere:nth-child(2){
        animation-delay: -0.5s;
    }
    .sphere:nth-child(3) {
        animation-delay: -1s;
    }
    @keyframes rotate{
        to{
            transform: rotate(360deg);
        }
    }
    /* 让小球的圆环的上下穿梭 */
    @keyframes overlapping {
      to {
          z-index: 2;
      }
    }
    .sphere::after{
        content: '';
        position: absolute;
        width: 3em;
        height: 3em;
        border-radius: 50%;
        background-color: lightseagreen;
    }
  • 相关阅读:
    Qt5中QMessageBox::warning()的第一个参数写this时出错
    Qt5如何设置静态编译,解决生成的可执行文件打开出错问题
    SpringCloud OAuth2实现单点登录以及OAuth2源码原理解析
    Redis分区
    Redis持久化
    如何合理地估算线程池大小?
    并发减库存
    Java导出Excel
    电商促销后台逻辑
    Java8虚拟机内存模型
  • 原文地址:https://www.cnblogs.com/FlyingLiao/p/10550763.html
Copyright © 2011-2022 走看看