【问题标题】:How to make a loader that spins around text如何制作一个围绕文本旋转的加载器
【发布时间】:2020-11-10 02:43:45
【问题描述】:

我想让我的加载器围绕我的文本旋转。现在文本随着加载器旋转。如何制作固定位置的文字?

检查我的沙盒:https://codesandbox.io/s/compassionate-saha-c1te1?file=/src/App.js

import React, { Component } from "react";

import "./loader.scss";

class Loader extends Component {
  render() {
    return (
      <div className="loader-wrapper">
        <div className="loader-component">myLogo</div>
        <h3>please wait</h3>
      </div>
    );
  }
}

export default Loader;

.loader-component{
  margin-top: 20%;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #555;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 2s linear infinite;
  z-index: 9999;

}
.loader-wrapper{
  display: flex;
  flex-flow: column;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 99999;
  h3{
    font-weight: 600;
    font-size: 26px;
    line-height: 36px;
    color: #FFFFFF;
  }
  span{
    font-size: 15px;
    line-height: 24px;
    color: #FFFFFF;
  }
}
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

【问题讨论】:

    标签: css reactjs animation loader


    【解决方案1】:

    更改您的标记以分隔元素,然后应用新的 css。

    class Loader extends Component {
      render() {
        return (
          <div className="loader-wrapper">
            <div className="logo-spinner">
              <div className="loader-component" />
              <p>logo</p>
            </div>
            <h3>please wait</h3>
          </div>
        );
      }
    }
    

    CSS

    .loader-wrapper{
      .logo-spinner {
        position:fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        .loader-component{ 
          border: 5px solid #f3f3f3;
          border-top: 5px solid #555;
          border-radius: 50%;
          width: 50px;
          height: 50px;
          animation: spin 2s linear infinite;
          z-index: 9999;
        }
      }
      display: flex;
      flex-flow: column;
      align-items: center;
      position: fixed;
      top: 0;
      left: 0;
      bottom: 0;
      right: 0;
      background: rgba(0, 0, 0, 0.72);
      z-index: 99999;
      h3{
        position: fixed;
        font-weight: 600;
        font-size: 26px;
        line-height: 36px;
        color: #FFFFFF;
        top: 55%;
      }
      p {
        padding: 0;
        margin: 0;
        position:fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      }
      span{
        font-size: 15px;
        line-height: 24px;
        color: #FFFFFF;
      }
    }
    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
    
    

    这也将使加载器在页面上完全居中。如果您希望它在页面上更高,您可以调整顶部。

    这是更新后的沙盒: https://codesandbox.io/s/vigilant-frog-zf6sj?file=/src/component/Loader.js:68-343

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      相关资源
      最近更新 更多