svg - SVG 蒙版不适用于多个变换
问题描述
我有几个头像框架(在圆桌周围的椅子上),我在反应中动态生成。我正在尝试将 a 添加clip-path
到框架中,这将根据框架的形状剪辑图像。
我在下面为其中一个帧提供了(生成的)代码,即使剪辑区域正好落在图像上(使用 chrome 的检查器检查),它似乎也不起作用。我已经尝试使用剪辑路径和蒙版(包含在下面的代码中)来剪辑/屏蔽它。如果有人能解释为什么这不起作用,那就太好了?
<svg viewBox="0 0 2000 2000">
<g class="avatar_container">
<defs>
<symbol id="avatarFrame" viewBox="-12 -8 135 135">
<path d="M55.5 121.217l8.313-11.856A50.55 50.55 0 00106.049 59.5 50.55 50.55 0 0055.5 8.951 50.55 50.55 0 004.951 59.5a50.55 50.55 0 0042.237 49.861z"></path>
</symbol>
<use id="frame-def" xlink:href="#avatarFrame" x="0" y="0" width="100" height="100"></use>
<mask id="frame-mask" x="0" y="0" width="2200" height="2200">
<rect x="0" y="0" width="2200" height="2200" fill="#000"></rect>
<use x="1067.525" y="100" transform="rotate(315,1117.525,400)" xlink:href="#frame-def" fill="#fff"></use>
</mask>
<clipPath id="frame-clip">
<use x="1067.525" y="100" transform="rotate(315,1117.525,400)" xlink:href="#frame-def"></use>
</clipPath>
</defs>
<g class="avatar" transform="rotate(315,1117.525,400)" mask="url(#frame-mask)">
<image xlink:href="https://via.placeholder.com/100" x="1067.525" y="100" transform="rotate(-315,1117.525,150)" width="100" height="100"></image>
</g>
<use id="frame" class="avatar_frame" xlink:href="#frame-def" transform="rotate(315,1117.525,400)" x="1067.525" y="100" width="100" height="100" fill="none" stroke="#545454" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></use>
</g>
解决方案
推荐阅读
- html - 在移动网络搜索结果中显示网站图标
- excel - 如何使用结构化表引用在 SumIfs 公式中使用比较运算符
- python - 如何修改此函数,以便使用特定算法打印 1 与其参数之间的整数?
- powerbi - 除了递归之外,是否有更快/更有效的替代方法来从 M/PowerQuery 中的列表中查找值最接近的匹配项?
- sql - Teradata SQL:失败 [2616:22003] 计算期间发生数字溢出
- html - 手风琴的加减号
- elasticsearch - 如何从 Elasticsearch 中的嵌套数据类型查询中获取所有结果?
- c# - 带有浮点算术检查的流下
- python - Gunicorn 的 1 个网络工作者是否总是意味着只有 1 个进程?
- java - Mockito:轮询等待验证