Recently, when developing a small program, I encountered a requirement to implement a circular percentage progress bar, similar to the following design diagram: As a newbie, I felt that it would be difficult to implement, so I went to Baidu to see how others did it, but I didn’t find a satisfactory one. Either it was a static implementation, or it required a lot of DOM operations. It is better to avoid direct DOM operations in mini programs. The following is a dynamic implementation I made in the form of a Vue component. Here is the effect diagram first: EffectImplementation stepsDraw a pie chart .pie { display: inline-block; position: relative; width: 150px; height: 150px; margin-top: 40px; border-radius: 50%; background: #ccc; background-image: linear-gradient(to right, transparent 50%, #4479FD 0); color: transparent; text-align: center; } Achieve proportion effect This is achieved by adding pseudo-element occlusion and movement. The code is as follows: .pie::before { content: ''; position: absolute; top: 0; left: 50%; width: 50%; height: 100%; border-radius: 0 100% 100% 0 / 50%; background-color: inherit; transform-origin: left; animation: spin 5s linear infinite, bg 10s step-end infinite; } @keyframes spin { to { transform: rotate(.5turn); } } @keyframes bg { 50% { background: #4479FD; } } Using the CSS animation delay property Change the animation time above to 50, 100 respectively, so that you can directly pass the corresponding delay seconds in animation-delay , for example, -60s will be displayed at 60% animation-play-state: paused; animation-delay: -60s; Achieving a torus shape Add a positioned div directly in the div <div class="pie"> <div class="pie-inner"> {{num}}% </div> </div> Add a constant speed animation startAnimate (step, limit, speed) { setTimeout(() => { // num is a percentage if (this.num < limit) { this.num += step this.startAnimate(step, limit, speed) } else { this.num = limit } }, speed) } Bind calculated properties to animation-delay Convert num into corresponding delay seconds in real time computed: { delay () { return `-${this.num}s` } } SummarizeSo far, a dynamic circular percentage progress bar has been basically realized, but it is not perfect yet. If you have any comments or questions, please feel free to raise them. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Mysql command line mode access operation mysql database operation
>>: Analysis of the Principle and Method of Implementing Linux Disk Partition
Preface In some cases, we only know the intranet ...
1. Introduction When the amount of data in the da...
Today I accidentally saw the parameter slave_exec...
This article introduces 5 ways to solve the 1px b...
Table of contents Preliminary work Backend constr...
Introduction to Positioning in CSS position attri...
In web development, you often encounter characters...
In this project, the Docker container is used to ...
1. Back button Use history.back() to create a bro...
Written in front When we operate the database in ...
1. Basic Concepts //Any container can be specifie...
Table of contents 1. Falling into the pit 2. Stru...
In website construction, you will always encounter...
This article shares the specific code of JavaScri...
Table of contents 1.v-model 2. Binding properties...