我正在使用 svg 和 d3,我需要在 div 的中心和中间画一个圆。如何计算相同的坐标?
谢谢
最佳答案
你可以像这样获取div的中心:
var $this = $(this); // targeted div
var offset = $this.offset();
var width = $this.width();
var height = $this.height();
var centerX = offset.left + width / 2;
var centerY = offset.top + height / 2;
其中centerX和centerY是中心的坐标。
关于javascript - 查找 div 内中心点和中点的 x 和 y 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22338459/