gpt4 book ai didi

javascript - 从 Javascript 插入时 SVG 不起作用

转载 作者:行者123 更新时间:2023-11-29 23:08:07 24 4
gpt4 key购买 nike

<分区>

如果我在 SVG 中创建任何绘图,而不是将代码放在 HTML 文件中,我会从 JS 文件(使用 document.createElement('svg'))插入,svg 和它的所有笔画都以 0x0 大小呈现。

class Spinner {

constructor(target) {

this.target = document.getElementById(target);

const spinner = document.createElement('svg');
spinner.setAttribute('width', '100');
spinner.setAttribute('height', '100');

const spinnerPath = document.createElement('circle');
spinnerPath.setAttribute('fill', 'red');
spinnerPath.setAttribute('stroke', 'black');
spinnerPath.setAttribute('stroke-width', '3');
spinnerPath.setAttribute('cx', '50');
spinnerPath.setAttribute('cy', '50');
spinnerPath.setAttribute('r', '40');

spinner.append(spinnerPath);

this.target.append(spinner);

}

}

new Spinner('here');
<div id="here"></div>

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com