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
MySQL 8.0 compressed package installation method,...
Table of contents Written in front 1. Ngixn image...
Table of contents 1. What is reflection? 2. Refle...
Table of contents 1: Front-end handwritten paging...
First: via text/HTML var txt1="<h1>Tex...
One demand Generally speaking, a company has mult...
This article example shares the implementation me...
View the IP address of the Container docker inspe...
1. Install Tomcat 1. Find the tomcat image on Doc...
During the development process, I often encounter...
Table of contents Short Polling Long-Polling WebS...
This article shares the specific steps of install...
Publish Over SSH Plugin Usage Before using Publis...
Recently, when doing homework, I needed to nest a ...
need: In background management, there are often d...