I am using position : fixed
for a div for stick that div on top of the page, but when i use offset().top
for its child value, it gives different values on scrolling. i tried like :
CSS :
.parent{
position : fixed;
top : 0px;
}
.child{
height : 20px;
margin-top : 10px;
}
JS :
console.log($(".child").offset().top);
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.
$(".child").position()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With