Original link https://github.com/XboxYan/no… A button is probably one of the most common components on a web page. Most of them are unremarkable. If you come across such a button, would you be tempted to click it a few more times? Usually the first reaction to this kind of effect may be to use The effect is even more shocking. Of course, Generate Particles Apart from the <button> button <i></i> <i></i> <i></i> <i></i> <i></i> ... </button> Generally speaking, I don’t like this approach very much. It has too many tags, the structure is not beautiful, and it may cause other impacts on existing pages (in many cases it is not convenient to modify the original Then let’s take a look at the 1.box-shadow Let's first look at .button::before{ position: absolute; content: ''; width: 5px; height: 5px; border-radius: 50%; background-color: #ff0081; box-shadow: 10px 10px #ff0081,15px 0px 0 2px #ff0081,20px 15px 0 3px #ff0081,...;/*Infinite overlay*/ } There is some effect, it just takes more time to debug. The position and size of the particles are mainly determined by the offset and expansion. However, the offset here can only be in 2. Background-image In CSS3, .myclass { background: background1, background2, /*...*/ backgroundN; } Here we can use .button::before{ position: absolute; content: ''; left: -2em; right: -2em; top: -2em; bottom: -2em; pointer-events: none; background-repeat: no-repeat; background-image: radial-gradient(circle, #ff0081 20%, transparent 0), radial-gradient(circle, #ff0081 20%, transparent 0), radial-gradient(circle, #ff0081 20%, transparent 0), radial-gradient(circle, #ff0081 20%, transparent 0), ...; background-size: 10% 10%, 20% 20%, 15% 15%,...; background-position: 18% 40%, 20% 31%, 30% 30%,...; } Here, This creates a simple particle effect. Get moving Although The animation effect is very simple, which is the process of particles spreading outward from the center and gradually disappearing. transition Let’s first look at the .button::before{ transition:.75s background-position ease-in-out,75s background-size ease-in-out; } .button:hover::before{ background-position: 5% 44%, -5% 20%, 7% 5%...; background-size: 0% 0%; } Of course, it is definitely not ideal to set it directly like this. When the mouse leaves, it will shrink back. The effect is as follows We need the mouse not to shrink back when it leaves. How can we achieve this? It's very simple. Just set .button:hover::before{ background-position: 5% 44%, -5% 20%, 7% 5%...; background-size: 0% 0%; transition:.75s background-position ease-in-out,75s background-size ease-in-out; } Does this feel a little better? Click here to view. What should we do if we want to make particle animation appear when clicking? Here we need to use the If we follow the .button:active::before{ background-position: 5% 44%, -5% 20%, 7% 5%...; background-size: 0% 0%; transition:.75s background-position ease-in-out,75s background-size ease-in-out; } Unfortunately, it can only be triggered when the button is pressed. Once the mouse is lifted, it disappears. At this time, we need to change the angle. You can imagine it this way, the default is divergent, then when you click it, it converges, and when you lift it, it will be restored to the previous divergent state. At the same time, you need to cancel the transition effect when you click, as follows .button::before { /*...*/ background-position: 5% 44%...;/*Diffusion state*/ background-size: 0% 0%; transition: background-position .5s ease-in-out, background-size .75s ease-in-out; } .button:active::before { transition:0s;/**Note to cancel the transition**/ background-size: 10% 10%, 20% 20%...; background-position: 18% 40%, 20% 31%,...; } You can check out this demo Why do we need animation The implementation principles of .button::before{ /*...*/ animation: bubbles ease-in-out .75s forwards; } .button:active::before { animation: none; /*Note that the animation can be canceled here*/ background-size: 0; } @keyframes bubbles { 0% { background-position: 18% 40%, ...; } 50% { background-position: 10% 44%, ...; } 100% { background-position: 5% 44%, ...; background-size: 0% 0%; } } You can view the source code here. The only drawback may be that the initialization animation will be executed once. summary The above introduces a pure CSS implementation of a particle animation button. The advantages are obvious. You can copy There are still some shortcomings. For example, the positioning above is densely packed with workload. It is recommended that these functions be fine-tuned after the overall project is completed. You can also try to make some visualization tools to reduce the workload. That’s it. Summarize The above is the CSS particle dynamic button effect introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you! |
<<: Detailed explanation of three ways to wrap text in el-table header
>>: Summary of MySQL InnoDB architecture
MYSQL version: MySQL Community Server 5.7.17, ins...
1.1 Download the binary installation package wget...
During normal project development, if the MySQL v...
Introduction Animation allows you to easily imple...
Table of contents 1. Background running jobs 2. U...
Table of contents Deploy httpd with docker contai...
What is bond NIC bond is a technology that is com...
Table of contents Declare fonts with font-face co...
Table of contents Project Background Improvement ...
Purpose: Treat Station A as the secondary directo...
<br />Web Design and Production Test Part I ...
Summary HTML: element plus v-cloak CSS: [v-cloak]...
Get the current time: select current_timestamp; O...
Table of contents 1. Database Overview 1.1 Develo...
Table of contents Method 1: set: It is not a data...