Use CSS to achieve circular wave effect

Use CSS to achieve circular wave effect

I often see some circular wave graphics on mobile devices to display the amount. At first I thought this effect could only be created using canvas, but later I found that it could also be created using CSS.

Principle: We all know that setting border-radius:50% will turn it into a circle. If it is less than 50%, it will actually become an irregular circle. We can take advantage of this feature and use pseudo-classes plus transform animation to achieve a wave effect.

Let’s take a look at the effect diagram first:

//css code

.wave {
        position: relative; 
    width: 200px;
    height: 200px;
    background: @color;
    border: 5px solid #76daff;
    border-radius: 50%;
    overflow: hidden;
}
.wave-box::before,
.wave-box::after {
      content: '';
      position: absolute;
      top: 0;
      left: 50%;
      width: 400px;
      height: 400px;
      border-radius: 45%;
      -webkit-transform: translate(-50%, -70%);
      transform: translate(-50%, -70%);
      background: rgba(255, 255, 255, 0.5);
      -webkit-animation: rotate 10s linear infinite;
      animation: rotate 10s linear infinite;
      z-index: 10;
}
@keyframes rotate {
  50% {
            -webkit-transform: translate(-50%, -75%) rotate(180deg);
            transform: translate(-50%, -75%) rotate(180deg);
  }
  100% {
            -webkit-transform: translate(-50%, -70%) rotate(180deg);
            transform: translate(-50%, -70%) rotate(180deg);
  }
}
//Or it is more convenient to use a precompiled language, here we use less
.wave(@width; @height; @color) {
    position: relative; 
    width: @width;
    height: @height;
    background: @color;
    border: 5px solid @color;
    border-radius: 50%;
    overflow: hidden;
    &::before,
    &::after {
        content: '';
        position: absolute;
        top: 0;
        left: 50%;
        width: @width * 2;
        height: @height * 2;
        border-radius: 45%;
        transform: translate(-50%, -70%);
        background: rgba(255,255,255,0.5);
        animation: rotate 10s linear infinite;
        z-index: 10;
    }
    &::after {
        border-radius: 47%;
        background: rgba(255,255,255,0.5);
        animation: rotate 10s linear -5s infinite;
        z-index: 20;
    }
}
//Call .wave-box {
    .wave(200px; 200px; #76daff);
}
<!-- Called on the page -->
<div class="wave-box"></div>

Summarize

The above is what I introduced to you about using CSS to achieve circular wave effects. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  A brief discussion on the synchronization solution between MySQL and redis cache

>>:  Web standards learning to understand the separation of structure and presentation

Recommend

How to use bar charts in Vue and modify the configuration yourself

1. Import echart in HTML file <!-- Import echa...

IDEA complete code to connect to MySQL database and perform query operations

1. Write a Mysql link setting page first package ...

Detailed explanation of long transaction examples in MySQL

Preface: The "Getting Started with MySQL&quo...

Linux uses join -a1 to merge two files

To merge the following two files, merge them toge...

Vue3 AST parser-source code analysis

Table of contents 1. Generate AST abstract syntax...

CSS to achieve chat bubble effect

1. Rendering JD Effect Simulation Effect 2. Princ...

Steps to install GRUB on Linux server

How to Install GRUB for Linux Server You cannot u...

Summary of the characteristics of SQL mode in MySQL

Preface The SQL mode affects the SQL syntax that ...

How to completely delete the MySQL 8.0 service under Linux

Before reading this article, it is best to have a...

SQL to implement time series dislocation restoration case

Table of contents 1. Requirements description 2. ...

Zabbix implements monitoring of multiple mysql processes

Three MySQL instance processes are started on one...

JS ES6 asynchronous solution

Table of contents Initially using the callback fu...