起始偏移

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

startOffset 屬性定義了在將路徑轉換為 <textPath> 元素的座標系統後,相對於路徑起點的當前文字的初始偏移量。

你可以將此屬性與以下 SVG 元素一起使用

示例

html
<svg viewBox="0 0 220 100" xmlns="http://www.w3.org/2000/svg">
  <path
    id="path1"
    fill="none"
    stroke="red"
    d="M10,90 Q90,90 90,45 Q90,10 50,10 Q10,10 10,40 Q10,70 45,70 Q70,70 75,50" />
  <path
    id="path2"
    fill="none"
    stroke="red"
    d="M130,90 Q210,90 210,45 Q210,10 170,10 Q130,10 130,40 Q130,70 165,70 Q190,70 195,50" />

  <text>
    <textPath href="#path1" startOffset="0">
      Quick brown fox jumps over the lazy dog.
    </textPath>
  </text>

  <text>
    <textPath href="#path2" startOffset="40">
      Quick brown fox jumps over the lazy dog.
    </textPath>
  </text>
</svg>

用法說明

<length-percentage> | <number>
預設值 0
可動畫的
<length-percentage>

長度表示 <textPath> 元素的當前使用者座標系統中沿路徑的距離。

如果給出百分比,則起始偏移量表示沿整個路徑的百分比距離。因此,0% 表示路徑的起點,100% 表示路徑的終點。

<number>

此值表示 <textPath> 元素當前使用者座標系統中沿路徑的距離。

注意: 允許使用負值和大於路徑長度的值(例如,150%)。

規範

規範
Scalable Vector Graphics (SVG) 2
# TextPathElementStartOffsetAttribute

瀏覽器相容性