Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate element-position

I would like to calculate the vertical position of a <div> with jQuery.

How would I do this?

Here's an illustration describing what I mean:

enter image description here

like image 908
Patrik Avatar asked Apr 21 '11 15:04

Patrik


1 Answers

I think you're looking for its offset from the top of the page, right?

$('#div').scrollTop();

If that's not it, maybe the offset would work:

$('#div').offset().top;

Okay, now that it needs to be relative to the parent, try this:

$('#div').position().top;
like image 99
Blender Avatar answered Sep 23 '22 20:09

Blender