I need to find distance between top of the window to the element. I can calculate that distance using offsetTop, But in offsetTop it only gives element's distance from top of the window, What I want is to decrease the distance when user scrolls up. And increase the distance when user scrolls down. So how to achieve this?
Use .getBoundingClientRect().
See more info here: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
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