stroke-dashoffset
stroke-dashoffset 屬性是一個表示屬性,用於定義與關聯的虛線陣列(dash array)的渲染偏移量。
注意: 作為一個表示屬性,stroke-dashoffset 也有一個對應的 CSS 屬性:stroke-dashoffset。當兩者都被指定時,CSS 屬性具有更高的優先順序。
你可以將此屬性與以下 SVG 元素一起使用
示例
html
<svg viewBox="-3 0 33 10" xmlns="http://www.w3.org/2000/svg">
<!-- No dash array -->
<line x1="0" y1="1" x2="30" y2="1" stroke="black" />
<!-- No dash offset -->
<line x1="0" y1="3" x2="30" y2="3" stroke="black" stroke-dasharray="3 1" />
<!--
The start of the dash array computation
is pulled by 3 user units
-->
<line
x1="0"
y1="5"
x2="30"
y2="5"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="3" />
<!--
The start of the dash array computation
is pushed by 3 user units
-->
<line
x1="0"
y1="7"
x2="30"
y2="7"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="-3" />
<!--
The start of the dash array computation
is pulled by 1 user units which ends up
in the same rendering as the previous example
-->
<line
x1="0"
y1="9"
x2="30"
y2="9"
stroke="black"
stroke-dasharray="3 1"
stroke-dashoffset="1" />
<!--
the following red lines highlight the
offset of the dash array for each line
-->
<path d="M0,5 h-3 M0,7 h3 M0,9 h-1" stroke="rgb(255 0 0 / 50%)" />
</svg>
用法說明
| 值 | <percentage> | <length> |
|---|---|
| 預設值 | 0 |
| 可動畫的 | 是 |
偏移量通常以使用者單位表示,並根據 pathLength 進行解析。但如果使用 <percentage>,則該值被解析為當前視口的百分比。
規範
| 規範 |
|---|
| Scalable Vector Graphics (SVG) 2 # StrokeDashoffsetProperty |
瀏覽器相容性
載入中…
另見
- CSS
stroke-dashoffset屬性