jQuery scroll事件

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中是同样的.atom

相关文章
相关标签/搜索