Arjun Arjun -5 years ago 219
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download