下拉无法刷新Ajax页面,jQuery下拉滚动条刷新 ajax获取数据

效果就是看百度图片的时候,滚动条拉到底部,将会出现动态刷新的图样。

已经做成了插件

下面是文件 jquery.bottomScrollLoading.js 中的代码

/**

* Created by ipqhjjybj on 14-3-7.

*/

;(function($){

var $bottomScrollLoading;

$.fn.bottomScrollLoading = function(settings){

return this.each(function(){

$bottomScrollLoading.init($(this), settings);

});

};

$bottomScrollLoading = $.bottomScrollLoading = {

init: function(outer, settings){

this.appendTo = settings.appendTo | $("body");

this.outer = outer; //这是滚动的视图

this.range = settings.range || -700; //距下边界长度/单位px

this.maxnum = settings.maxnum || 20; //设置加载最多次数

this.ajaxData = settings.ajaxData || {};

this.isLoading = false;

this.num = 1;

if ('undefined' === typeof this.ajaxData.dataType || !$.inArray(this.ajaxData.dataType, ('html', 'json'))) {

this.ajaxData.dataType = 'html';

}

this.tmp_success = this.ajaxData.success;

this.ajaxData.success = function(ret){

sl = $bottomScrollLoading;

sl.isLoading = false;

$("#ipq_loading").remove();

if('function' === typeof sl.tmp_success){

sl.tmp_success(ret);

}

}

$(this.outer).scroll(function(){

var sl = $bottomScrollLoading;

var scrollPos = $(this).scrollTop();

var totalHeight = parseFloat($(sl.outer).height()) + parseFloat(scrollPos);

if( (false === sl.isLoading) && ( $(document).height()-sl.range) <= totalHeight && sl.num <= sl.maxnum){

sl.isLoading = true;

$("#content").append("

717128fde90e6346068c2b0d9000a075.gif");

sl.sendRequest();

sl.num = sl.num + 1;

}

});

},

sendRequest:function(){

$.ajax(this.ajaxData);

}

}

})(jQuery);

/*

how to use it

$(window).bottomScrollLoading({

out:$(document),

ajaxData:{

url: "test5.html",

success:function(ret){

alert(ret);

$("#content").append("

");//如果想修改 loading的图片,请修改这里

}

}

});

*/

使用时加上头文件

之后加上代码

$(window).bottomScrollLoading({

out:$(document),

ajaxData:{

url: "test5.html",

success:function(ret){

//alert(ret);

$("#content").append("

");

}

}

});

放上我的 demo页面好了

html>

this is a scroll test;

页面下拉自动加载内容

hello world test DIV

制作这个插件的时候,参考了 http://blog.csdn.net/saindy5828/article/details/7756315这里的代码

如果对加载时的loading图片不满意的。可以去修改  jquery.bottomScrollLoading.js  中的 $(body)附加的图片部分。。

第一次做jQuery插件。。

看来js水平进步了很多。。

附送一个demo.zip 来演示 demo

hlyblog.net

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值