滑動載入之ScrollLoad.js

來源:互聯網
上載者:User

標籤:regex   amp   date()   result   ice   create   stat   alt   成功   

var ScrollLoadInit = {    //當前所在頁    PageIndex: 1,    //是否還在傳輸中    Is_Submit: false,    //返回的值以為空白/已經讀完了    IsFinally: false,    //預設總頁數    PageCount: 99999,    //預設資料類型    DataType:"json"}function ScrollLoad(type, data, url, callback) {    $(window).scroll(function () {        var nScrollTop = $(this).scrollTop();        if (nScrollTop >= $(document).height() - $(window).height() - 50) {            var result = ToGetData(type, data, url);            callback(result);        }    })}//post請求function ScrollLoadPost(data, url, callback) {    ScrollLoad("post", data, url, callback);}//get請求function ScrollLoadGet(data, url, callback) {    ScrollLoad("get", data, url, callback);}function ToGetData(type, data, url) {    //定義請求成功後返回的對象    var ResultData = "";    //返回一些不能繼續載入的情況    if (ScrollLoadInit.Is_Submit) {        return "";    }    if (ScrollLoadInit.PageIndex > ScrollLoadInit.PageCount) {        return "";    }    //表示傳輸中,阻止請求    ScrollLoadInit.Is_Submit = true;    //禁止緩衝機制    $.ajaxSetup({ cache: false }); $.ajaxSetup({ cache: false });    data.pageIndex = ScrollLoadInit.PageIndex;    data.timestamp = new Date().getTime();    //url.indexOf(‘?‘) != -1 ? url += "&" : url += "?";    $.ajax({        type: type,        data: data,        url: url,        dataType:ScrollLoadInit.DataType,        async: false,        success: function (result) {            ScrollLoadInit.Is_Submit = false;            if (result == "") {                ScrollLoadInit.IsFinally = true;                ScrollLoadInit.PageCount = ScrollLoadInit.PageIndex - 1;             }            ResultData = result;        }    })    ScrollLoadInit.PageIndex += 1;    return ResultData;}
ScrollLoad.js

案例:

<script>    function GetQueryString(name)    {        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");        var r = window.location.search.substr(1).match(reg);        if(r!=null)return  unescape(r[2]); return null;    }    ScrollLoadInit.PageIndex = 2;    ScrollLoadInit.PageCount = @Model.TotalPageCount;    ScrollLoadInit.DataType = ‘json‘;    //每次請求都會帶上的參數    var data = {"status":GetQueryString("status")};    //請求的地址    var url = "/Mobile/Order/GetList";    ScrollLoadGet(data, url, callback);    //填充資料    function callback(msg) {        if(msg!=undefined && msg!=""){            if(msg.data!=undefined){  $(".more").remove();                $(msg.data).each(function(i,v){                    var item=‘                        <div class="gs">                            <div class="bt"><div class="b1">訂單編號:‘+v.OrderNumber+‘</div><div class="b2">‘+v.StatusStr+‘</div></div>                            <div class="con">                                <div class="l"><img src="‘+v.ProductImgUrl+‘" width="100%" ></div>                                <div class="r">                                    <div class="b"><span class="b1">‘+v.ProductTitle+‘</span><span class="b2">¥‘+v.Price+‘</span></div>                                    <div class="b"><span class="b1 hui">下單時間:‘+v.CreateTimeStr+‘</span><span class="b2">ב+v.NumStr+‘</span></div>                                    <div class="s">¥‘+v.PayAmount+‘</div>                                </div>                            </div>                        </div>                       ‘;                    $(".cons").append(item);                });                }            }        }</script>
View Code

 

滑動載入之ScrollLoad.js

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.