aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/svg/element/textpath/index.html
blob: fc629c0b3cf4e0eaf1122bcd4973a60c8c746d82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: textPath
slug: Web/SVG/Element/textPath
tags:
  - SVG
  - SVG文本内容
  - 元素
  - 参考
  - 需要兼容表
translation_of: Web/SVG/Element/textPath
---
<div>{{SVGRef}}</div>

<p>除了笔直地绘制一行文字以外, SVG 也可以根据 {{ SVGElement("path") }} 元素的形状来放置文字。 只要在<code>textPath</code>元素内部放置文本,并通过其<code>xlink:href</code>属性值引用{{ SVGElement("path") }}元素,我们就可以让文字块呈现在{{ SVGElement("path") }}元素给定的路径上了。</p>

<h2 id="用法">用法</h2>

<p>{{svginfo}}</p>

<h2 id="示例">示例</h2>

<pre class="brush: html">&lt;svg width="100%" height="100%" viewBox="0 0 1000 300"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"&gt;
  &lt;defs&gt;
    &lt;path id="MyPath"
          d="M 100 200
             C 200 100 300   0 400 100
             C 500 200 600 300 700 200
             C 800 100 900 100 900 100" /&gt;
  &lt;/defs&gt;

  &lt;use xlink:href="#MyPath" fill="none" stroke="red"  /&gt;

  &lt;text font-family="Verdana" font-size="42.5"&gt;
    &lt;textPath xlink:href="#MyPath"&gt;
      We go up, then we go down, then up again
    &lt;/textPath&gt;
  &lt;/text&gt;

  &lt;!-- Show outline of the viewport using 'rect' element --&gt;
  &lt;rect x="1" y="1" width="998" height="298"
        fill="none" stroke="black" stroke-width="2" /&gt;
&lt;/svg&gt;</pre>

<p>即时结果:</p>

<p>{{EmbedLiveSample("Example",500,175)}}</p>

<h2 id="属性">属性</h2>

<h3 id="全局属性">全局属性</h3>

<ul>
 <li><a href="/en/SVG/Attribute#ConditionalProccessing" title="en/SVG/Attribute#ConditionalProccessing">条件处理属性</a> »</li>
 <li><a href="/en/SVG/Attribute#Core" title="en/SVG/Attribute#Core">核心属性</a> »</li>
 <li><a href="/en/SVG/Attribute#GraphicalEvent" title="en/SVG/Attribute#GraphicalEvent">图形事件属性</a> »</li>
 <li><a href="/en/SVG/Attribute#Presentation" title="en/SVG/Attribute#Presentation">外观属性</a> »</li>
 <li><a href="/en/SVG/Attribute#XLink" title="en/SVG/Attribute#XLink">Xlink属性</a> »</li>
 <li>{{ SVGAttr("class") }}</li>
 <li>{{ SVGAttr("style") }}</li>
 <li>{{ SVGAttr("externalResourcesRequired") }}</li>
</ul>

<h3 id="专有属性">专有属性</h3>

<ul>
 <li>{{ SVGAttr("startOffset") }}</li>
 <li>{{ SVGAttr("method") }}</li>
 <li>{{ SVGAttr("spacing") }}</li>
 <li>{{ SVGAttr("xlink:href") }}</li>
</ul>

<h2 id="DOM_接口">DOM 接口</h2>

<p>该元素实现了<code><a href="/en/DOM/SVGTextPathElement" title="en/DOM/SVGTextPathElement">SVGTextPathElement</a></code>接口。</p>