我正在尝试使用SVG创建一个固定的剪辑掩码。这个掩码必须有position: fixed,因为我希望它与浏览器一起滚动。
我有以下HTML/SVG和SCSS:
<div class="table"></div>
<div class="clipping-mask">
<svg>
<defs>
<clipPath id="clipping">
<circle cx="50%" cy="15%" r="15%" />
</clipPath>
</defs>
</svg>
</div>SCSS:
.table {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url("../images/table.jpg");
background-size: contain;
background-repeat: no-repeat;
background-position: center;
clip-path: url(#clipping);
}
.clipping-mask {
position: absolute;
top: 0;
width: 100%;
height: 100%;
svg {
width: 100%;
height: 100%;
}
}上面的代码正确地剪辑了背景,只显示了圆圈内的位置。唯一的问题是它不是固定的(就像CSS position: fixed中的那样),因此它不会在浏览器中滚动。

这有可能吗?我需要它是SVG,因为我想在某个点将形状转换成一个矩形。
发布于 2015-03-02 14:46:27
您是否尝试过修复<img>的位置,并仅对其应用了剪裁路径或掩码?当使用objectBoundingBox坐标定义时,应用于HTML元素的掩码和裁剪路径通常工作得最好。
https://stackoverflow.com/questions/28811051
复制相似问题