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

  1. .placeholder {
  2. position: relative;
  3. overflow: hidden;
  4. }
  5.  
  6. .placeholder:before {
  7. content: " ";
  8. position: absolute;
  9. top:;
  10. right:;
  11. bottom:;
  12. left:;
  13. background: linear-gradient(
  14. to right,
  15. rgba(255, 255, 255, 0) 0%,
  16. rgba(255, 255, 255, 0.35) 8%,
  17. rgba(255, 255, 255, 0) 16%
  18. );
  19. animation: scanner 0.9s linear infinite;
  20. z-index:;
  21. }
  22.  
  23. @keyframes scanner {
  24. 0% {
  25. transform: translateX(-20%);
  26. }
  27.  
  28. 100% {
  29. transform: translateX(170%);
  30. }
  31. }
  32.  
  33. .placeholder__headline {
  34. height: 22px;
  35. background-color: var(--placeholder-color);
  36. margin-bottom: 20px;
  37. }
  38.  
  39. .placeholder__text {
  40. height: 16px;
  41. background-color: var(--placeholder-color);
  42. margin-bottom: 8px;
  43. }
  44.  
  45. .placeholder__image {
  46. border-radius: 50%;
  47. background-color: var(--placeholder-color);
  48. height: 100px;
  49. }
  50.  
  51. .placeholder__text--small {
  52. width: 25%;
  53. }
  54.  
  55. .placeholder__text--medium {
  56. width: 50%;
  57. }
  58.  
  59. .placeholder__text--large {
  60. width: 75%;
  61. }
  62.  
  63. .placeholder__text--block {
  64. width: 100%;
  65. }

Placeholder.jxs:

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

[React] Create an Animate Content Placeholder for Loading State in React的更多相关文章

  1. [React] Use CSS Transitions to Avoid a Flash of Loading State

    Based on research at Facebook, we know that if a user sees a flash of loading state, they perceive t ...

  2. React Js之组件(Component)与state

    React Js组件: 组件(Component)是为了更好的维护我们的应用,可以在不影响其他的组件的情况下更新或者更改组件. state:是标记数据的来源,我们使state比较简单和单一,如果我们有 ...

  3. 《React Native 精解与实战》书籍连载「React Native 源码学习方法及其他资源」

    此系列文章将整合我的 React 视频教程与 React Native 书籍中的精华部分,给大家介绍 React Native 源码学习方法及其他资源. 最后的章节给大家介绍 React Native ...

  4. 《React Native 精解与实战》书籍连载「React Native 底层原理」

    此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...

  5. 《React Native 精解与实战》书籍连载「React 与 React Native 简介」

    此文是我的出版书籍<React Native 精解与实战>连载分享,此书由机械工业出版社出版,书中详解了 React Native 框架底层原理.React Native 组件布局.组件与 ...

  6. React子组件怎么改变父组件的state

    React子组件怎么改变父组件的state 1.父组件 class Father extends React.Component { construtor(props){ super(props); ...

  7. [Svelte 3] Use await block to wait for a promise and handle loading state in Svelte 3

    Most web applications have to deal with asynchronous data at some point. Svelte 3 apps are no differ ...

  8. React virtual DOM explained in simple English/简单语言解释React的虚拟DOM

    初学React,其中一个很重要的概念是虚拟DOM,看了一篇文章,顺带翻译一下. If you are using React or learning React, you must have hear ...

  9. CSS3效果:animate实现点点点loading动画效果(一)

    实现如图所示的点点点loading效果: 一:CSS3 animation实现代码 html代码: 提交订单中<span class="ani_dot">...< ...

随机推荐

  1. Kafka性能调优 - Kafka优化的方法

    今天,我们将讨论Kafka Performance Tuning.在本文“Kafka性能调优”中,我们将描述在设置集群配置时需要注意的配置.此外,我们将讨论Tuning Kafka Producers ...

  2. python基础 — 数据组合

    a = [1, 2, 3] b = [4, 5, 6] c = [7, 8, 9] for x, y, z in (a, b, c): print(x, y, x) print(type(zip(a, ...

  3. 解决python中的Non-UTF-8 code starting with ‘\xbs4’ in file错误

    出现错误如下图: 主要原因为编辑python脚本使用的编辑器编码有问题.我使用的编辑器是notepad++,由于没有做Python语言编辑配置,默认使用的是ANSI编码(右下角位置有编码格式),如下: ...

  4. golang程序因未知错误崩溃时如何记录异常

    开发服务器程序时如果未经过充分测试, 服务稳定运行一段时间后会突然崩溃退出.一般是因为程序中出现了某个未捕获的异常. 这类问题属于偶现的,且需要服务器运行一段时间之后才会出现,难以定位有问题的代码段. ...

  5. Numpy学习笔记(上篇)

    目录 Numpy学习笔记(上篇) 一.Jupyter Notebook的基本使用 二.Jpuyter Notebook的魔法命令 1.%run 2.%timeit & %%timeit 3.% ...

  6. TweenLite参数用法中文介绍

    TweenLite是一个缓动的类包,功能强大,并且易于使用,为了更多的(E文欠佳的.初学的)朋友了解它,使用它,特此翻译了一下TweenLite类文档中的说明文件,主要是对参数的说明,希望对大家有用. ...

  7. Locust性能测试_百度案例

    一.安装: 1.Locust在PyPI上可用,可以通过pip或easy_install安装:pip install locustio                2.查看Locust可用选项:loc ...

  8. Centos7 在线安装开发环境 jdk1.8+mysql+tomcat

    写在最前 刚刚开始接触Linux,并折腾着在服务器上部署自己的项目,当然作为一个后端开发人员,必不可少的东西肯定是 JDK Mysql Tomcat容器 每天记录一天,每天进步一点点~~ 1.更新系统 ...

  9. Disruptor与Netty实现百万级(十)

    实体对象: import java.io.Serializable; public class TranslatorData implements Serializable { private sta ...

  10. JS函数的三种方式

    函数,一段能够自动完成某些功能的代码块,函数的出现,既解决了重复使用重一功能的需求,又可以避免代码的臃肿性. 使用函数有两个要求:必须调用后才可以执行;函数名不要和关键字以及系统函数相同; 函数主要有 ...