繁体   English   中英

SVG <textPath> 没有出现(使用ReactJS)

[英]SVG <textPath> not showing up (with ReactJS)

我无法使<textPath>遵循我的SVG路径。 我在控制台中看到这个是0x0,但是我无法更改它。 我也有一个font-size: 4vw中有#svg_text所以我真的不知道发生了什么。

这是我的JavaScript代码:

return(
        <div key={i*3} id="svg_container">
        <svg
        viewBox="0 0 1532.82 818.45"
        id="svg">
          <path d="M1716,795.37C1392.31,283.32,716.07,130.88,204,454.54"
          transform="translate(-203.18 -283.05)"
          fill="transparent" stroke="#000"/>

          <text id="svg_text">
            <textPath xlinkHref="#curve">
              this is a test - this is a test
            </textPath>
          </text>
          </svg>
        </div>
      )
    }   })

这是我的CSS代码:

#svg_container{
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
}

#svg {
  width: 80vw;
  height: 80vh;
}


#svg_text{
  font-size: 4vw;
  font-family: Dia-Bold;
  color: white;
}

任何帮助将不胜感激。

尝试这个。 看起来React不支持textPath,所以你可以做的是

   const  textPath = `<textPath xlinkHref="#curve">
          this is a test - this is a test
        </textPath>`;

        <text id="svg_text" dangerouslySetInnerHTML={{__html: textPath }}></text>

在根svg元素处为svg和xlink添加xmlns,如下所示

<svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" viewBox="0 0 1532.82 818.45" id="svg">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM