我正在尝试使用内联 SVG 元素渲染 React 组件,该元素沿路径有文本。这是从 render 方法返回的内容:
<div className="textsvg">
<svg width="100%" height="100%" viewBox="-50 -50 100 100">
<defs>
<path id="textPathTop" d={`
M 0 40
A 40,40 0 0 1 0,-40
A 40,40 0 0 1 0,40`}></path>
<path id="textPathBottom" d={`
M 0 -41.8
A 41.8,41.8 0 0 0 0,41.8
A 41.8,41.8 0 0 0 0,-41.8`}></path>
</defs>
<use xlinkHref="#textPathBottom" fill="none" stroke="red"></use>
<text fill="red" fontSize="4.5"><textPath xlinkHref="#textPathBottom">We go up, then we go down, then up again</textPath></text>
</svg>
</div>
Run Code Online (Sandbox Code Playgroud)
这显示了“我们向上,然后我们向下,然后再次向上”文本,但只是从 0,0 开始的水平直线。
将生成的 html 复制到codepen …