开发者

Measuring the window offset

开发者 https://www.devze.com 2023-03-14 03:37 出处:网络
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?

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 f开发者_C百科ixed element (which is relative to the viewport top) and the relative object (which is relative to the top of the document)


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


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


document.body.offsetWidth;

and

document.body.offsetHeight;

By using these javascript functions you can get actual width and height of the browser window

0

精彩评论

暂无评论...
验证码 换一张
取 消