2

I have a fixed position object and I want to know how far it is from the top of the window.

For some reason when I use .offset and .top, it gives me the distance to the top of the entire page, not just the window.

  var sidebar = jQuery('.sidebar');
  var sidebarHeight = sidebar.offset().top + $sidebar.height();

How do I get the distance just to the top of the window?

James Mitchell
  • 2,387
  • 4
  • 29
  • 59
  • Please see this answer: https://stackoverflow.com/a/9880571/5236719 – JDewitt Sep 13 '17 at 18:18
  • 2
    Possible duplicate of [Determine distance from the top of a div to top of window with javascript](https://stackoverflow.com/questions/9880472/determine-distance-from-the-top-of-a-div-to-top-of-window-with-javascript) – Kodaloid Sep 13 '17 at 18:20

0 Answers0