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
Form provides two ways of data transmission - get ...
Table of contents Introduction to NIS Network env...
This article summarizes some simple principles of...
Parent File import React, { useState } from '...
This article shares the installation tutorial of ...
When playing music, the lyrics will gradually fil...
Table of contents need: Ideas: lesson: Share the ...
Table of contents 1. What is a design pattern? 2....
The question is referenced from: https://www.zhih...
1. Introduction Why do we need indexes? In genera...
Recently, I need to query all the fields in a rel...
This article shares the specific code of js to im...
Preface : Today I was asked, "Have you carefu...
In the previous article, we learned about the pas...
This article introduces MySQL string interception...