When loading network data, in order to improve the user experience, a circular loading animation is usually used, or a Skeleton Screen is used as a placeholder. Compared with the loading animation, the Skeleton Screen effect is more vivid and easier to implement. A simple Skeleton Screen can be implemented using CSS. Ideas
Start by building the skeleton The skeleton structure is very simple, just put a few block-level elements you like in it. <div class='screen-root'> <ul> <li/> <li/> <li/> </ul> </div> You see, it’s that simple. CSS Coloring The skeleton screen we often see looks like this In order to facilitate description and enhance contrast, I will first make a ghost version First, use the CSS Label linear-gradient() can create a linear gradient image with multiple colors. For more information, see here li{ background-image: linear-gradient(90deg, #ff0000 25%, #41de6a 37%, #ff0000 63%); width: 100%; height: 0.6rem; list-style: none; } In actual use, replace the gradient image with a normal color, such as: Make it move All that's left to do is animate the green in the middle Can you think of any way to make it move? What is used here is to stretch the background image, dynamically set the background positioning percentage, change the background positioning, and thus calculate the different offset values of the image relative to the container, so as to achieve the animation effect. li{ background-image: linear-gradient(90deg, #ff0000 25%, #41de6a 37%, #ff0000 63%); width: 100%; height: 0.6rem; list-style: none; background-size: 400% 100%; background-position: 100% 50%; animation: skeleton-loading 1.4s ease infinite; } @keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } } Here, two values are set for When you use a percentage to set Some students may ask, setting You can try setting different values for background-size, observe how it behaves, and think about why it happens. Finally, use the keyframe animation to set @keyframes skeleton-loading { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } } Assuming the container width is (100px-400px)*100% = -300px The actual offset of the last frame (100px-400px)*0% = 0 The animation process is actually the process of a linear background image that is 3 times the width of the container and its offset relative to the container changes from Summarize This is the end of this article about how to implement Skeleton Screen with CSS. For more information about how to implement Skeleton Screen with CSS, please search previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! |
<<: This article will show you how to use SQL CASE WHEN in detail
>>: HTML dynamically loads css styles and js scripts example
Notice! ! ! This situation can actually be avoide...
Anti-shake: Prevent repeated clicks from triggeri...
Prepare war package 1. Prepare the existing Sprin...
Preface When a 403 cross-origin error occurs No &...
Table of contents Preface: Step 1: Find the free ...
This article summarizes some simple principles of...
Table of contents 1. Optional Chaining 2. Null va...
Table of contents 1. What kind of backup is a dat...
Install PostgreSQL 11 on CentOS 7 PostgreSQL: The...
I just finished installing MySQL 5.7.19 in the ea...
A sophomore asked me how to install and configure...
1. Call the parent component method directly thro...
Table of contents I. Overview 2. Conventional mul...
Table of contents Preface 1. Introduction to one-...
Table of contents Multi-application deployment 1-...