backgroundToday, I was browsing CodePen and saw a very interesting effect: CodePen Demo -- Material Design Menu By Bennett Feely There are still some points worth exploring and learning about this effect. Let’s take a look at it below. How to achieve a similar effect?First of all, think about it, if you were asked to achieve the above effect, what would you do? Here I briefly list some possible solutions:
Go through them one by one quickly. Using box-shadow If you use <div class="g-container"> <div class="g-item"></div> </div> .g-container { position: relative; width: 400px; height: 300px; overflow: hidden; } .g-item { position: absolute; width: 48px; height: 48px; border-radius: 50%; background: #fff; top: 20px; left: 20px; box-shadow: 0 0 0 0 #fff; transition: box-shadow .3s linear; &:hover { box-shadow: 0 0 0 420px #fff; } } The core is:
The effect is as follows: The overall animation is simulated, but it has two fatal problems:
So, although Use radial-gradient to achieve Next, we can use <div class="g-container"></div> @property --size { syntax: '<length>'; inherits: false; initial-value: 24px; } .g-container { position: relative; width: 400px; height: 300px; overflow: hidden; background: radial-gradient(circle at 44px 44px, #fff 0, #fff var(--size), transparent var(--size), transparent 0); transition: --size .3s linear; &:hover { --size: 450px; } } By controlling the radial gradient animation effect, we can change the original small circle background into a large circle background when hovering. The effect is as follows: Emmm, the effect is indeed restored, but the problem is also fatal:
CodePen Demo -- radial-gradient zoom in animation Emmm, there is another method, which is to use scaling So here, if you want to achieve the above effect, the core is:
Using clip-path to achieve dynamic area clippingSo, here, we actually need a dynamic area cropping. In this article of mine - How to implement overflow: hidden without using overflow: hidden? , introduced several ways to clip elements in CSS, and among them, the most suitable one for this effect is - clip-path. Using <div class="g-container"></div> .g-container { position: relative; width: 400px; height: 300px; overflow: hidden; transition: clip-path .3s linear; clip-path: circle(20px at 44px 44px); background: #fff; &:hover { clip-path: circle(460px at 44px 44px); } } We just need to use The effect is as follows: In this way, we can perfectly achieve the effect of the title image, and the built-in DOM elements can be directly written into this div. <div class="g-container"> <ul> <li>11111</li> <li>22222</li> <li>33333</li> <li>44444</li> </ul> </div> The effect is as follows: CodePen Demo -- clip-path zoom in animation This is a very interesting technique, using clip-path to achieve dynamic area clipping. I hope everyone can master it. This is the end of this article about how to use clip-path in JS to implement dynamic area cropping. For more relevant clip-path area cropping content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL series multi-table join query 92 and 99 syntax examples detailed tutorial
>>: CSS clear float clear:both example code
Due to work requirements, I recently spent some t...
1. Create a database: create data data _name; Two...
Experimental environment A minimally installed Ce...
Detailed explanation of MySQL instance with SSD s...
Enough of small talk <br />Based on the lar...
1. CSS realizes fixed width on the left and adapt...
Copy code The code is as follows: <pre> <...
1. Check whether MySQL is installed yum list inst...
1. Command method Run the nginx service in the cr...
1. First, you need to know what will trigger the v...
Table of contents Scenario Code Implementation Su...
Core code /*-------------------------------- Find...
There are two ways to delete data in MySQL, one i...
Table of contents 1. Pull the centos image 2. Bui...
Table of contents Preface Implementation ideas Ef...