Created
February 28, 2017 02:26
-
-
Save chengjianhua/3b171d572f46b5ffa447cb856179b044 to your computer and use it in GitHub Desktop.
jQuery judge whether scroll to the bottom of window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
$(document).ready(function(){ | |
alert($(window).height()); //浏览器时下窗口可视区域高度 | |
alert($(document).height()); //浏览器时下窗口文档的高度 | |
alert($(document.body).height());//浏览器时下窗口文档body的高度 | |
alert($(document.body).outerHeight(true));//浏览器时下窗口文档body的总高度 包括border padding margin | |
alert($(window).width()); //浏览器时下窗口可视区域宽度 | |
alert($(document).width());//浏览器时下窗口文档对于象宽度 | |
alert($(document.body).width());//浏览器时下窗口文档body的高度 | |
alert($(document.body).outerWidth(true));//浏览器时下窗口文档body的总宽度 包括border padding margin | |
var win_height=$(window).height(); | |
var doc_height=$(document).height(); | |
var scroll_top=$(document).scrollTop(); | |
/* | |
doc_height是文档的高度,scroll_top是滚动条上部离文档顶部的高度,window_height表示窗口高度。 | |
当scroll_top == 0 时,表示滚动条已经到达窗口顶部。 | |
当scroll_top + window_height >= doc_height 时,表示滚动条已经到达窗口底部。 | |
*/ | |
//判断滚动条是否到达窗口底部 | |
$(window).bind('scroll', function(){ //绑定滚动事件 | |
if($(document).scrollTop() + $(window).height() >= $(document).height()){ | |
console.log(win_height); | |
console.log($(document).scrollTop()); | |
console.log(doc_height); | |
//...... | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment