Measuring the window offset

心已入冬 提交于 2020-01-14 22:53:47

问题


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)


回答1:


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




回答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




回答3:


document.body.offsetWidth;

and

document.body.offsetHeight;

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



来源:https://stackoverflow.com/questions/6422561/measuring-the-window-offset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!