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
Overview I have recently started learning MySQL r...
The previous article introduced several methods f...
question Nginx takes $remote_addr as the real IP ...
Database application is an indispensable part of ...
This article lists the most commonly used image c...
Use CSS to create a 3D photo wall. The specific c...
This article shares the specific code of uniapp t...
MultiTail is a software used to monitor multiple ...
1. Make sure the system has the required libaio s...
1. Install Howdy: howdy project address sudo add-...
How to solve the timeout problem when pip is used...
Preface: MySQL master-slave architecture should b...
Intro Previously, our docker images were stored i...
MySQL is a free relational database with a huge u...
Table of contents Summarize Summarize When the ar...