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:;
right:;
bottom:;
left:;
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:;
} @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" />;
}

[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. js中引用类型Math一些常用的方法和属性

    js中有一种引用类型叫做Math,和Global属于单体内置对象,里面有一些非常常用的数学方法和数学常量 常用数学常量 Math.E; // 自然对数的底数Math.LN10 10的自然对数 Math ...

  2. gorm 批量插入数据

    使用gorm 插入数据的时候,根据官方文档可以使用Create或者FirstOrCreate(). 但是官方没有提供批量插入数据的方法. 根据github的 issue得知,我们可以通过自己拼接sql ...

  3. 【软件设计师】CPU的功能和组成

    CPU的功能 CPU的组成

  4. VirtualBox导入OVA文件文档教程

    1 2 修改框住的路径,最好不要在C盘 3 取消检查更新 4 5 6 7 8 9 10 11 等待加载完成:加载完成后 OVA文件导入成功 作者:含笑半步颠√ 博客链接:https://www.cnb ...

  5. C#解压、压缩高级用法

    压缩:(可以吧要排除的文件去掉) /// <summary> /// 压缩文件夹 /// </summary> /// <param name="folder& ...

  6. 2.5_Database Interface ODBC数据源及案例

    分类 用户数据源 用户创建的数据源,称为“用户数据源”.此时只有创建者才能使用,并且只能在所定义的机器上运行.任何用户都不能使用其他用户创建的用户数据源. 系统数据源 所有用户在Windows下以服务 ...

  7. asp.net mvc 使用bootstrap的模态框插件modal

    编译器:vs2012 jquery版本:jquery-1.10.2.js bootstrap:bootstrap.js v3.0.0,包含modal插件 我们要实现一个使用模态框展示从服务器获取的数据 ...

  8. power shell导出文件夹目录递归

    --获取目录:Get-ChildItem --递归目录:-Recurse --选择想要导出的目录参数,如:文件名,时间,权限等:Select-Object Name, LastWriteTime, M ...

  9. sql 分组后重复数据取时间最新的一条记录

    1.取时间最新的记录 不分组有重复(多条CreateTime一样的都是最新记录) select * from test t where pid in ( select PId from Test t ...

  10. R_基本统计分析_06

    summary()提供基础的统计信息 sapply(x,FUN,options)可以指定统计函数 fivenum()可以返回图基五数 Hmisc 中的describe(data)返回变量,观测的变量, ...