前端 CSS 经典:图层放大的 hover 效果

效果

思路

设置 3 层元素,最上层元素使用 clip-path 裁剪成圆,hover 改变圆大小,添加过渡效果。

实现代码

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="initial-scale=1.0, user-scalable=no, width=device-width"
    />
    <title>document</title>
    <style>
      body {
        background: #000;
      }

      .avatar {
        background: url(../../../images/demo/img.jpg);
        background-size: cover;
        height: 200px;
        width: 200px;
        border-radius: 50%;
        cursor: pointer;
        position: relative;
      }

      .avatar::after,
      .avatar::before {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: 50%;
      }

      .avatar::before {
        background: rgba(0, 0, 0, 0.5);
      }

      .avatar::after {
        background: inherit;
        clip-path: circle(0% at 50% 50%);
        transition: 0.3s;
      }

      .avatar:hover::after {
        clip-path: circle(50% at 50% 50%);
      }
    </style>
  </head>
  <body>
    <div class="avatar"></div>
    <script></script>
  </body>
</html>
相关推荐
Z***u6593 小时前
前端性能测试实践
前端
xhxxx3 小时前
prototype 是遗产,proto 是族谱:一文吃透 JS 原型链
前端·javascript
倾墨3 小时前
Bytebot源码学习
前端
用户93816912553603 小时前
VUE3项目--集成Sass
前端
S***H2834 小时前
Vue语音识别案例
前端·vue.js·语音识别
啦啦9118864 小时前
【版本更新】Edge 浏览器 v142.0.3595.94 绿色增强版+官方安装包
前端·edge
蚂蚁集团数据体验技术5 小时前
一个可以补充 Mermaid 的可视化组件库 Infographic
前端·javascript·llm
LQW_home5 小时前
前端展示 接受springboot Flux数据demo
前端·css·css3
q***d1735 小时前
前端增强现实案例
前端·ar
IT_陈寒5 小时前
Vite 3.0 重磅升级:5个你必须掌握的优化技巧和实战应用
前端·人工智能·后端