Arjun Arjun - 7 months ago 35
CSS Question

offset().top is not working as expected in if parent element is fixed

I am using

position : fixed
for a div for stick that div on top of the page, but when i use
for its child value, it gives different values on scrolling. i tried like :


position : fixed;
top : 0px;
height : 20px;
margin-top : 10px;

JS :


the above JS code give different results when i scrolling the page.


Use .position() to get the current coordinates of an element relative to its offset parent. The .offset() method is gives you the coordinates relative to the entire document.