1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| $(function() { var i =0; //设置当前页数 if (!NeuF) var NeuF = {}; NeuF.ScrollPage = function (obj, options, callback) { var _defaultOptions = {delay: 500, marginBottom: 200}; //默认配置:延迟时间delay和滚动条距离底部距离marginBottom options = $.extend(_defaultOptions, options); this.isScrolling = false; //是否在滚动 this.oriPos = 0; //原始位置 this.curPos = 0; //当前位置 var me = this; //顶层 var $obj = (typeof obj == "string") ? $("#" + obj) : $(obj); //绑定滚动事件 $obj.scroll(function (ev) { me.curPos = $obj.scrollTop(); if ($(window).height() + $(window).scrollTop() >= $(document.body).height() - options.marginBottom) { if (me.isScrolling == true) return; me.isScrolling = true; setTimeout(function () { me.isScrolling = false; }, options.delay); //重复触发间隔毫秒 if (typeof callback == "function") callback.call(null, me.curPos - me.oriPos); } ; me.oriPos = me.curPos; }); }; $(function () { window.scrollTo(0, 0); //每次F5刷新把滚动条置顶 function show() { $.ajax({ url: '/e/action/get_news_index.php',//自己的域名 type: 'POST', data: { "next": i, 'table': 'news', 'action': 'getmorenews', 'limit': 10, 'small_length': 120 }, dataType: 'html', beforeSend: function () { $("#loadmore").show().html('<img src="/307/skin/ecms103/images/loading.gif"/>正在努力加载中...'); $('#loadmore').attr('disabled', 'disabled'); }, success: function (data) { if (data) { $("#showajaxnews").append(data); $("#loadmore").removeAttr('disabled'); $("#loadmore").html('滚动加载更多'); i++; } else { $("#loadmore").show().html("已全部加载完毕!"); console.log(data); $('#loadmore').attr('disabled', 'disabled'); return false; } } }); }; show(); //marginBottom表示滚动条离底部的距离,0表示滚动到最底部才加载,可以根据需要修改 new NeuF.ScrollPage(window, {delay: 1000, marginBottom: 0}, function (offset) { if (offset > 0) { setTimeout(show,1000) } }); }); });
|