码迷,mamicode.com
首页 > 其他好文 > 详细

页面延时加载技术

时间:2016-12-02 22:00:24      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:border   nbsp   ajax加载   for   pos   doc   get   bottom   页面   

绑定scroll事件 滚动条到达底部时 解除scroll事件 ajax加载数据 如果数据没全部载入 再次绑定scroll事件

绑定scroll事件 滚动条到达底部时 解除scroll事件 ajax加载数据 如果数据没全部载入 再次绑定scroll事件

$(document).ready(function() {
    $(window).bind("scroll", GetData);

    function GetData() {
        var windowHeight = $(window).height();
        var scrollHeight = $(document).scrollTop();
        var screenBottom = windowHeight + scrollHeight;
        var documentHeight = $(document).height();
        if (screenBottom >= documentHeight) {
            $(window).unbind();
            $.ajax({
                type: "post",
                url: "GetData.aspx",
                data: "action=data",
                success: function(data) {
                    data = eval("(" + data + ")");
                    if (data.ret = 1) {
                        var html = "";
                        for (var i = 0; i < 12; i++) {
                            html += ‘<div style=" border:1px solid; width:198px; float:left; height:200px" >‘ + i + ‘</div>‘;
                        }
                        $("#div_main").append(html);
                        $(window).bind("scroll", GetData);
                    }
                }
            })

        }
    }
});

 

页面延时加载技术

标签:border   nbsp   ajax加载   for   pos   doc   get   bottom   页面   

原文地址:http://www.cnblogs.com/ndood/p/6127222.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!