前端 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>
相关推荐
kyriewen15 分钟前
我给 61 个前端库排了两次名,最多差了 46 位
前端·javascript·程序员
亲亲小宝宝鸭43 分钟前
Cesium启动:TLE数据是如何变成轨迹线的
前端·cesium
阿里云云原生1 小时前
对话即构建,在 AgentCore 构建 Agent 就是这么简单
前端·agent
夕水2 小时前
我给我的诗写了个后台,顺手写了 一个组件库ew-solid-ui
前端·javascript·typescript
狗头大军之江苏分军2 小时前
前端转行干能干什么?我转行试了下(被迫)
前端·后端
孟陬2 小时前
Foobar 技术周刊#2:约会已死?用户急剧下滑,约会App大概率会弱化约会属性转向轻陪伴。我有个建议:
前端·后端·rust
parade岁月3 小时前
VTable Guild 3.0.0 发布,面向 Vue 3 的 ProTable 式业务表格
前端
xurileidian3 小时前
第 17 篇 · 边玩边学Python · for 遍历 enumerate 与 zip
java·前端·python
掘金安东尼4 小时前
更多审查智能体,更少盲区:GitHub Copilot 代码审查是怎么做的
前端·github copilot
Hilaku7 小时前
2026 年了,jQuery 真的该死了吗?
前端·javascript·程序员