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. 函数的练习1——python编程从入门到实践

    8-1 消息: 编写一个名为display_message()的函数,它打印一个句子指出你在本章学的是什么.调用这个函数,确认显示的消息正确无误. def display_message(): pri ...

  2. logback 日志相关

    日志相关: logback:https://www.cnblogs.com/gavincoder/p/10091757.html https://www.cnblogs.com/hhhshct/p/9 ...

  3. .net语音播放,自定义播报文字

    // using System.Speech.Synthesis; SpeechSynthesizer synth = new SpeechSynthesizer(); // Configure th ...

  4. GitHub预览网页[2019最新]

    GitHub预览网页 1. 创建仓库 2. 设置页面预览 3. 上传html 4. 访问网页 1. 创建仓库 登陆GitHub创建仓库 datamoko 添加基本信息: 仓库名.仓库描述,然后点击创建 ...

  5. isolate sqflite demo

    main.dart import 'package:flutter/material.dart'; import 'demo_isolates.dart'; import 'package:rxdar ...

  6. 入门Docker,你要下载什么?注册什么?

    此随笔根据前人经验改编并亲自实践.遇到问题提供出相应解决方法. 入门Docker,你要下载什么?注册什么? Docker.app你肯定是要下载的!此教程应用于MAC系统PC不保证适用 Docker f ...

  7. 1.工厂模式(Factory Method)

    注:图片来源于 https://www.cnblogs.com/-saligia-/p/10216752.html 工厂UML图解析: 工厂模式:client用户需要三步: 1.创建工厂: 2.生产产 ...

  8. 点击其它位置,div下拉菜单消失

    接下拉菜单那一篇: 加上点击其它位置,下拉菜单消失. 纯js写法: window.document.addEventListener('click', function(e) { var e = e ...

  9. Java8新特性概览

    Java8新特性简介 a)速度更快 1.对于JVM内存模型的新定义,将永久代从堆内存中移除,以前HotSpot JVM堆内存分为三块:1.年轻代  2.年老代  3.持久代  点击回顾 取而代之的是 ...

  10. vuex页面刷新数据丢失的解决办法

    在vue项目中用vuex来做全局的状态管理, 发现当刷新网页后,保存在vuex实例store里的数据会丢失. 原因: 因为store里的数据是保存在运行内存中的,当页面刷新时,页面会重新加载vue实例 ...