Home  >  Article  >  Web Front-end  >  jquery method to determine whether the scroll bar has reached the bottom or top

jquery method to determine whether the scroll bar has reached the bottom or top

高洛峰
高洛峰Original
2017-01-11 09:58:161077browse

$(document).height()  //是获取整个页面的高度
$(window).height()  //是获取当前也就是浏览器所能看到的页面的那部分的高度。这个大小在你缩放浏览器窗口大小时会改变,与document是不一样的
To get the top, you only need to get the top when scrollTop()==0;

To get the bottom, you only need to get scrollTop()>=$(document).height()-$(window). height() You can know that it has scrolled to the bottom;

$(document).scrollTop() 获取垂直滚动的距离  即当前滚动的地方的窗口顶端到整个页面顶端的距离;
$(document).scrollLeft() 这是获取水平滚动条的距离;

Example:

$(document).scroll(function(){
    $("#lb").text($(document).scrollTop());
})
<span id="lb" style="top:100px;left:100px;position:fixed;"></span><!--一个固定的span标记 滚动时-->
More jquery methods to determine whether the scroll bar has reached the bottom or top. For related articles, please pay attention to the PHP Chinese website!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn