Reputation: 2973
I am using svg and d3 and I need to draw a circle right at the center and middle of a div. How do I calculate the coordinates of the same?
Thanks
Upvotes: 0
Views: 1457
Reputation: 801
You can get center of div like this:
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;
Where centerX and centerY are the coordinates of center.
Upvotes: 3