开发者

How do I find the current window offset using javascript?

开发者 https://www.devze.com 2023-04-04 01:27 出处:网络
When I open a page, the window offset would be 0 but when i scroll through the page, the offset of t开发者_开发技巧he window would increase correspondingly? How can I find the window\'s offset at any

When I open a page, the window offset would be 0 but when i scroll through the page, the offset of t开发者_开发技巧he window would increase correspondingly? How can I find the window's offset at any particular point of my web page?


You can get the scroll offset of the window by using window.scrollX & window.scrollY. See the MDN article on scrollY for more information.

window.scrollY; // the current vertical scroll offset of the window

Just thought I would provide the non-jQuery version.


I don't know if I get the question, but for getting scroll offset use:

var scrollOffset = $(window).scrollTop();


The .offset() method is undefined for window object or window element therefore you should use the .scrollTop() method to solve your issue :)

0

精彩评论

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