Measuring the window offset

16,969

Solution 1

$(window).scrollTop() and $(window).scrollLeft() can be used to find scroll positions.

Solution 2

Using plain Javascript without jQuery should be window.pageXOffset and window.pageYOffset, which return the number of pixels offset by scrolling.

Source: https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY

Share:
16,969
Mild Fuzz
Author by

Mild Fuzz

Updated on June 26, 2022

Comments

  • Mild Fuzz
    Mild Fuzz almost 2 years

    Is there a way to measure the offset of the window in jQuery, in order than I might compare the positions of a 'fixed' element and a relatively positioned one?

    I need to be able to tell how far the window is scrolled so I can use the figure to calculate the difference between the height of the fixed element (which is relative to the viewport top) and the relative object (which is relative to the top of the document)