Pure HTML+CSS to achieve Element loading effect

Pure HTML+CSS to achieve Element loading effect

This is the effect of the Element UI loading component. It looks cool. Let’s implement it!

analyze

The animation consists of two parts:

The blue arc stretches from a point to a circle, and then shrinks from the circle to a point.

The parent node of the circle rotates with the circle

Code
html

<svg viewBox="25 25 50 50" class="box">
    <circle cx="50" cy="50" r="20" fill="none" class="circle"></circle>
</svg>

CSS
Default Style

.box {
    height: 200px;
    width: 200px;
    background: wheat;
}
.box .circle {
    stroke-width: 2;
    stroke: #409eff;
    stroke-linecap: round;
}

Add animation effects

/* Rotation animation */
@keyframes rotate {
    to {
        transform: rotate(1turn)
    }
}
/* Arc animation */
/* 125 is the circumference of the circle */
@keyframes circle {
    0% {
 /* State 1: Point */
        stroke-dasharray: 1 125;
        stroke-dashoffset: 0;
    }
    50% {
 /* State 2: Circle */
        stroke-dasharray: 120, 125;
        stroke-dashoffset: 0;
    }
    to {
 /* State 3: Point (shrinking in the direction of rotation) */
        stroke-dasharray: 120 125;
        stroke-dashoffset: -125px;
    }
}
.box {
  /* ...same as above*/
  animation: rotate 2s linear infinite;
}
.circle {
  /* ...same as above*/
  animation: circle 2s infinite;
}

Finally, remove the background

Online code demo https://jsbin.com/yarufoy/edit?html,css,output

This is the end of this article about how to achieve Element loading effect with pure HTML+CSS. For more relevant content about how to achieve loading with HTML+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!

<<:  Sample code for implementing the Olympic rings with pure HTML+CSS

>>:  Detailed explanation of HTML basics (Part 1)

Recommend

Practical method of upgrading PHP to 5.6 in Linux

1: Check the PHP version after entering the termi...

Why do we need Map when we already have Object in JavaScript?

Table of contents 1. Don’t treat objects as Maps ...

How to run nginx in Docker and mount the local directory into the image

1 Pull the image from hup docker pull nginx 2 Cre...

jQuery implements a simple carousel effect

Hello everyone, today I will share with you the i...

How to import/save/load/delete images locally in Docker

1. Docker imports local images Sometimes we copy ...

Linux installation apache server configuration process

Prepare the bags Install Check if Apache is alrea...

Solve the problem of docker container exiting immediately after starting

Recently I was looking at how Docker allows conta...

Analyze Tomcat architecture principles to architecture design

Table of contents 1. Learning Objectives 1.1. Mas...

Detailed tutorial of using stimulsoft.reports.js with vue-cli

vue-cli uses stimulsoft.reports.js (nanny-level t...

Analysis of GTK treeview principle and usage

The GtkTreeView component is an advanced componen...

Detailed explanation of how to use the Vue license plate input component

A simple license plate input component (vue) for ...

Comprehensive explanation of CocosCreator hot update

Table of contents Preface What is Hot Change Coco...

Methods and techniques for quickly displaying web page images

1. Use .gifs rather than .jpgs. GIFs are smaller ...

Html/Css (the first must-read guide for beginners)

1. Understanding the meaning of web standards-Why...