javascript - 查找 div 内中心点和中点的 x 和 y 坐标

标签 javascript html svg d3.js html5-canvas

我正在使用 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/

相关文章:

javascript - jQuery:根据我们选择的数量创建多个输入字段

html - 我的媒体查询不起作用。包括元标记;链接 rel 链接

javascript - 如何堆叠 rects 各自的前一个 rect 的高度?

javascript - svg 路径不可见

javascript - 当内联 block div 高度增长时防止内容流动

javascript - 如何在 Angular typescript 或 jquery 中全局更新变量?

Javascript 没有将代码放在 ID div 中

html - 用线性渐变着色后将图像定位在 div 中

javascript - D3 sunburst 图 : Setting arc. cornerRadius() causes invalid path with arcTween

javascript - 如何选择第一个td