<clipPath>
示例
html
<svg viewBox="0 0 100 100">
<clipPath id="myClip">
<!--
Everything outside the circle will be
clipped and therefore invisible.
-->
<circle cx="40" cy="35" r="35" />
</clipPath>
<!-- The original black heart, for reference -->
<path
id="heart"
d="M10,30 A20,20,0,0,1,50,30 A20,20,0,0,1,90,30 Q90,60,50,90 Q10,60,10,30 Z" />
<!--
Only the portion of the red heart
inside the clip circle is visible.
-->
<use clip-path="url(#myClip)" href="#heart" fill="red" />
</svg>
css
/* With a touch of CSS for browsers who *
* implemented the r Geometry Property. */
@keyframes openYourHeart {
from {
r: 0;
}
to {
r: 60px;
}
}
#myClip circle {
animation: openYourHeart 15s infinite;
}
剪輯路徑在概念上等效於引用元素的自定義視口。因此,它會影響元素的渲染,但不會影響元素的固有幾何形狀。被剪輯元素(即,透過 clip-path 屬性或引用元素的子元素引用 <clipPath> 元素的元素)的邊界框必須保持與未被剪輯時相同。
預設情況下,在剪輯區域上不會分派 pointer-events。例如,半徑為 10 的圓被剪輯到半徑為 5 的圓,則在較小半徑之外將不會接收“點選”事件。
屬性
clipPathUnits-
定義
<clipPath>元素內容的座標系。值型別:userSpaceOnUse|objectBoundingBox;預設值:userSpaceOnUse;可動畫:是
使用上下文
規範
| 規範 |
|---|
| CSS 遮罩模組級別 1 # ClipPathElement |
瀏覽器相容性
BCD 表格僅在啟用 JavaScript 的瀏覽器中載入。
相關
- 其他剪輯和遮罩 SVG 元素:
<mask> - 一些 CSS 屬性:
clip-path、pointer-events