【发布时间】:2022-01-20 01:07:11
【问题描述】:
for (el of chart.children) {
i++
previous__element = chart.children[i - 1]
if (el.classList.contains('rule')) {
//pass
} else {
line = el.children[0].children[0]
pos1 = previous__element.children[2].getBoundingClientRect()
position1 = {
top: pos1.top,
left: pos1.left,
}
pos2 = el.children[2].getBoundingClientRect()
console.log(previous__element.children[2])
console.log(el.children[2])
position2 = {
top: pos2.top,
left: pos2.left,
}
line.setAttribute('x1', Math.trunc(pos1.left))
line.setAttribute('y1', Math.trunc(pos1.top))
line.setAttribute('x2', Math.trunc(pos1.left))
line.setAttribute('y2', Math.trunc(pos1.top))
line.setAttribute('stroke', 'white')
}
}
获取输出的html:
由于某种原因,这实际上并没有显示线条,当在开发工具中将鼠标悬停在它们上方时,它显示高度和宽度为 0。我试图让线条连接到元素中的标记。
【问题讨论】:
-
你没有展示你是如何创建线条或
标签: javascript svg