我尝试使用javascipt创建动态svg
我的结果是
<svg xmlns='http://www.w3.org/2000/svg' viewBox='5279 1710 12.125 12.125'>
<g transform='translate(4311 1165)'>
<path fill='#fffff' d='M346.045,76.5a5.632,5.632,0,0,0,0,8.245,6.143,6.143,0,0,0,1.6-4.122A6' transform='translate(632.48 470.439)'/>
</g>
</svg>
Js代码获取以上图像:
const svg1 = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
svg1.setAttribute('viewBox', '5279 1710 12.125 12.125')
svg1.setAttribute('transform', 'translate(4311 1165)')
svg1.setAttribute('fill', 'fffff')
svg1.setAttribute('d', "M346.045,76.5a5.632,5.632,0,0,0,0,8.245,6.143,6.143,0,0,0,1.6-4.122A6'")
答案 0 :(得分:1)
您要弄错的是,您要在svg中添加'd'属性,而不是创建路径和g,请尝试
u