zoukankan      html  css  js  c++  java
  • [React + CSS3] Create an Animate Content Placeholder for Loading State in React

    We will create animated Content Placeholder as React component just like Facebook has when you load the page.

    Key points:

    1. For each elements on the DOM, you might need to create a placeholder components for that.

    2. Different size prop is important

    3. CSS animation

    .placeholder {
      position: relative;
      overflow: hidden;
    }
    
    .placeholder:before {
      content: " ";
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background: linear-gradient(
        to right,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.35) 8%,
        rgba(255, 255, 255, 0) 16%
      );
      animation: scanner 0.9s linear infinite;
      z-index: 1;
    }
    
    @keyframes scanner {
      0% {
        transform: translateX(-20%);
      }
    
      100% {
        transform: translateX(170%);
      }
    }
    
    .placeholder__headline {
      height: 22px;
      background-color: var(--placeholder-color);
      margin-bottom: 20px;
    }
    
    .placeholder__text {
      height: 16px;
      background-color: var(--placeholder-color);
      margin-bottom: 8px;
    }
    
    .placeholder__image {
      border-radius: 50%;
      background-color: var(--placeholder-color);
      height: 100px;
    }
    
    .placeholder__text--small {
      width: 25%;
    }
    
    .placeholder__text--medium {
      width: 50%;
    }
    
    .placeholder__text--large {
      width: 75%;
    }
    
    .placeholder__text--block {
      width: 100%;
    }

    Placeholder.jxs:

    import React from "react";
    import cx from "classnames";
    
    export default function Placeholder({ children, className }) {
      return <div className={cx(className, "placeholder")}>{children}</div>;
    }
    import React from "react";
    
    export default function Image() {
      return <div className="placeholder__image" />;
    }

  • 相关阅读:
    MYSQL设置允许所有访问
    解决ios端的H5,input有阴影的问题
    linux查看某个时间段的日志(sed -n)
    centos如何创建自启动脚本
    laravel做数据迁移的时候进行表的注释
    taro编译微信小程序,报错“未找到setmap.json文件”
    java百科常识
    spring自动装配
    top命令内容详解
    jemter 随机取数组里面的值放入请求
  • 原文地址:https://www.cnblogs.com/Answer1215/p/11648357.html
Copyright © 2011-2022 走看看