简体   繁体   中英

SVG <textPath> not showing up (with ReactJS)

I'm not able to make my <textPath> follows my SVG path. I see in the console that this one is at 0x0 but I'm not able to change it. I also have a font-size: 4vw to my #svg_text so I really don't know what's going on.

Here's my JavaScript code:

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>
      )
    }   })

Here's my CSS code:

#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;
}

Any help would be greatly appreciated.

Try this. Looks like textPath is not supported in React so what you can do is

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

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

add xmlns for svg and xlink at root svg element like below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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