I am trying to draw a circle after a few calculations are performed over top of a td. When I ran the the following code, it works:
$('#priority_one').width($('#learning_streams').width());
$('#priority_one').height($('#learning_streams').height());
var priority_one_paper = new Raphael('priority_one', $('#priority_one').width(), $('#priority_one').height());
var priority_one_circle = priority_one_paper.circle((pos.left).toFixed(0), (pos.top).toFixed(0), (width/2).toFixed(0));
priority_one_circle.attr('stroke','#000000');
But when I try to make it dynamic (the td changes depending on the input by the user) it no longer works. Code:
function circlePriorityOne() {
//priority_one is a div absolutely positioned over a table called learning_streams
//sets size of priority_one based off the table learning_streams
$('#priority_one').width($('#learning_streams').width());
$('#priority_one').height($('#learning_streams').height());
//creates the 'paper' to draw the circle on
var priority_one_paper = new Raphael('priority_one', $('#priority_one').width(), $('#priority_one').height());
var main = getMax(priority_one_count); //returns the id of the td to circle
var pos = $('#'+main).position();
var width = $('#'+main).width();
//using toFixed() to get rid of decimals
var priority_one_circle = priority_one_paper.circle((pos.left).toFixed(0), (pos.top).toFixed(0), (width/2).toFixed(0));
priority_one_circle.attr('stroke','#000000');
}
See anything wrong with this? Thanks.
You’re right. .position() gets the current position relative to a parent element.
You should use .offset() instead, which gets the current position relative to the
documentEdit
I’m not quite sure, because I haven’t tested it but it should do what you want^^