作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
如果我在 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>
我是一名优秀的程序员,十分优秀!