jQuery获取位置和尺寸相关函数:
函数名 | 作用 |
$(document).height() | 获取整个页面的高度。 |
$(window).height() | 获取当前也就是浏览器所能看到的页面的那部分的高度。这个大小在你缩放浏览器窗口大小时会改变,与document是不一样的。 |
scrollTop() | 获取匹配元素相对滚动条顶部的偏移。 |
scrollLeft() | 获取匹配元素相对滚动条左侧的偏移。 |
scroll([[data],fn]) | 当滚动条发生变化时触犯scroll事件 |
$(document).ready(function() { $(window).scroll(function() { if ($(document).scrollTop()<=0){ alert("滚动条已经到达顶部为0"); } if ($(document).scrollTop() >= $(document).height() - $(window).height()) { alert("滚动条已经到达底部为" + $(document).scrollTop()); } }); });