您的位置:首页 > Web前端 > JQuery

jQuery scroll事件

2014-04-03 18:24 357 查看
scroll事件适用于window对象,但也可滚动iframe框架与CSS overflow属性设置为scroll的元素。

$(document).ready(function () { //本人习惯这样写了
$(window).scroll(function () {
//$(window).scrollTop()这个方法是当前滚动条滚动的距离
//$(window).height()获取当前窗体的高度
//$(document).height()获取当前文档的高度
var bot = 50; //bot是底部距离的高度
if ((bot + $(window).scrollTop()) >= ($(document).height() - $(window).height())) {
//当底部基本距离+滚动的高度〉=文档的高度-窗体的高度时;
//我们需要去异步加载数据了
$.getJSON("url", { page: "2" }, function (str) { alert(str); });
}
});
});

注意:$(window).height()和$(document).height()的区别

补充一句$(window).scrollTop()和$(document).scrollTop()是没什么区别的,至少我在IE8中是一样的.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: