views:

36

answers:

1

I'm trying to figure out how to get the distance of an li from the top of the containing ul to allow me to position something next to it. However, using position() or offset() in jQuery seem to return a position from the top of the page or another higher element. Is there a plugin or any way to specify where you want the position calculation to come from?

+1  A: 

has been answered here

http://stackoverflow.com/questions/225563/get-relative-position-between-2-dom-elements-using-javascript

var o1 = $(element1).offset();
var o2 = $(element2).offset();
var dx = o1.left - o2.left;
var dy = o1.top - o2.top;
var distance = Math.sqrt(dx * dx + dy * dy);
Josh
Many thanks, I hadn't found that. Looks like an elegant solution. :)
Throlkim