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
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
2009-07-08 08:49:35
Many thanks, I hadn't found that. Looks like an elegant solution. :)
Throlkim
2009-07-08 08:51:17