How do I get the scroll position of a document?

2019-01-21 06:17发布

How to get the scroll position value of a document?

标签: jquery scroll
9条回答
倾城 Initia
2楼-- · 2019-01-21 06:55
$(document).height() //returns window height

$(document).scrollTop() //returns scroll position from top of document
查看更多
ら.Afraid
3楼-- · 2019-01-21 07:01

If you are using Jquery 1.6 or above, use prop to access the value.

$(document).prop('scrollHeight')

Previous versions used to get the value from attr but not post 1.6.

查看更多
该账号已被封号
4楼-- · 2019-01-21 07:03

Try this:

var scrollHeight = $(scrollable)[0] == document ? document.body.scrollHeight : $(scrollable)[0].scrollHeight;
查看更多
登录 后发表回答