使用jquery.more.js上滑加载更多
html:
<div id="more">
<div class="single_item">
<div class="date"></div>
<div class="author"></div>
<div class="title"></div>
</div>
<a href="javascript:;" class="get_more"></a>
</div>
<div id="nomore" style="text-align:center;color:gray"></div>
$(document).ready(function() {
var totalPage = {$totalPage};//总页数
var page = {$page}; //起始页
var pageSize = {$pageSize} //每页显示个数
$(window).scroll(function() {
if(totalPage-page>){
//滚动条到达底部加载
if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
setTimeout(function() {
$.ajax({
type: 'GET',
url: '?m=wap&c=vedio&a=art_more&typeid=93&yp=128&pageNum='+(page+),
success:function(data){
var msg=eval(data);
$.each(msg, function (i, item) {
$('.art-list').append("<li><a href="+item.art_link+">"+item.title+"</a></li>");
});
page=page+;
},
error:function(data){
$("#nomore").html("加载失败...");
setTimeout(function() {
$("#nomore").html();
}, );
},
});
}, );
}
}else{
$("#nomore").html("我是有底线的...");
setTimeout(function() {
$("#nomore").empty();
}, );
}
});
});
php:
// 连接数据库
require_once('connect.php');
$last = $_POST['last'];
$amount = $_POST['amount'];
$query = mysql_query("select * from article order by id desc limit $last,$amount");
while ($row = mysql_fetch_array($query)) {
$sayList[] = array(
'title' => $row['title'],
'author' => $row['id'],
'date' => date('m-d H:i', $row['addtime'])
);
}
echo json_encode($sayList);
返回json数据
[
{
"title": "xxx",
"author": "",
"date": "04-04 10:34"
},
{
"title": "xxx",
"author": "",
"date": "04-04 09:52"
},
{
"title": "xxx",
"author": "",
"date": "04-04 09:18"
},
{
"title": "xxx",
"author": "",
"date": "04-03 23:44"
},
{
"title": "xxx",
"author": "",
"date": "04-03 23:09"
},
{
"title": "xxx",
"author": "",
"date": "04-03 22:33"
},
{
"title": "xxx",
"author": "",
"date": "04-03 20:25"
},
{
"title": "xxx",
"author": "",
"date": "04-03 08:26"
},
{
"title": "xxx",
"author": "",
"date": "04-02 21:56"
},
{
"title": "xxx",
"author": "",
"date": "04-02 08:52"
}
]
jquery.more.js
/**
* 调用方法: $('#more').more({'url':'data.php'});
* amount 每次显示记录数
* address 请求的地址
* format 接受数据的格式
* template html记录DIV的class属性
* trigger 触发加载更多记录的class属性
* scroll 是否支持滚动触发加载
* offset 滚动触发加载时的偏移量
* data 自定义参数
* loading 加载时显示
*/
(function($) {
var target = null;
var template = null;
var lock = false;
var cur_last = ;
var variables = {
'last' :
}
var settings = {
'amount' : '',
'address' : 'comments.php',
'format' : 'json',
'template' : '.single_item',
'trigger' : '.get_more',
'scroll' : 'false',
'offset' : '',
'data' : {},
'loading' : '加载中...'
}
var methods = {
init: function(options) {
return this.each(function() {
if (options) {
$.extend(settings, options);
}
template = $(this).children(settings.template).wrap('<div/>').parent();
template.css('display', 'none');
$(this).append('<div class="loading">' + settings.loading + '</div>');
template.remove();
target = $(this);
if (settings.scroll == 'false') {
$(this).find(settings.trigger).bind('click.more', methods.get_data);
$(this).more('get_data');
} else {
if ($(this).height() <= $(this).attr('scrollHeight')) {
target.more('get_data', settings.amount * );
}
$(this).bind('scroll.more', methods.check_scroll);
}
})
},
check_scroll: function() {
if ((target.scrollTop() + target.height() + parseInt(settings.offset)) >= target.attr('scrollHeight') && lock == false) {
target.more('get_data');
}
},
debug: function() {
var debug_string = '';
$.each(variables, function(k, v) {
debug_string += k + ' : ' + v + '\n';
})
alert(debug_string);
},
remove: function() {
target.children(settings.trigger).unbind('.more');
target.unbind('.more')
target.children(settings.trigger).remove();
},
add_elements: function(data) {
var root = target
var counter = ;
if (data) {
$(data).each(function() {
counter++
var t = template
$.each(this, function(key, value) {
if (t.find('.' + key)) t.find('.' + key).html(value);
})
if (settings.scroll == 'true') {
root.children('.loading').before(t.html())
} else {
root.children(settings.trigger).before(t.html())
}
root.children(settings.template + ':last').attr('id', 'more_element_' + ((variables.last++) + ));
})
} else methods.remove()
// target.children('.loading').css('display', 'none');
if (counter < settings.amount){
methods.remove();
target.children('.loading').html("已经到底了");
}
},
get_data: function() {
var ile;
lock = true;
target.children(".loading").css('display', 'block');
$(settings.trigger).css('display', 'none');
if (typeof(arguments[]) == 'number') {
ile = arguments[];
} else {
ile = settings.amount;
}
if(variables.last >= cur_last) {
var postdata = settings.data;
postdata['last'] = variables.last;
postdata['amount'] = ile;
$.post(settings.address, postdata, function(data){
$(settings.trigger).css('display', 'block')
methods.add_elements(data)
lock = false;
}, settings.format);
cur_last = cur_last + ;
}
}
};
$.fn.more = function(method) {
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, ));
} else if (typeof method == 'object' || !method) {
return methods.init.apply(this, arguments);
} else $.error('Method ' + method + ' does not exist!');
}
$(document).ready(function() {
$(window).on('scroll', function() {
if ($(document).scrollTop() + $(window).height() > $(document).height() - ) {
$('.get_more').click();
}
});
});
})(jQuery)
使用jquery.more.js上滑加载更多的更多相关文章
- vue 上滑加载更多
移动端网页的上滑加载更多,其实就是滑动+分页的实现. <template> <div> <p class="footer-text">--{{f ...
- Android如何定制一个下拉刷新,上滑加载更多的容器
前言 下拉刷新和上滑加载更多,是一种比较常用的列表数据交互方式. android提供了原生的下拉刷新容器 SwipeRefreshLayout,可惜样式不能定制. 于是打算自己实现一个专用的.但是下拉 ...
- dropload.js 上滑加载,下拉刷新
https://github.com/ximan/dropload dropload a javascript implementation of pull to refresh and up to ...
- Android的ListView分页功能(上滑加载更多)
今天主要工作是将之前实现的各种ListView显示全部信息,优化成了每次加载几条数据,然后上滑的时候加载更多,底部显示一个进度条和一个文字提示,然后加载完毕后,将提示信息隐藏. 一边看教学视频一遍敲代 ...
- 移动端web页面上滑加载更多功能
背景介绍: 开发企业微信的一个应用,实现在企业微信中调用自己程序页面,页面加载多模块数据,向下滑加载更多,等等等等,一波三折 然后很早就成功了是这样实现的: html: <div id=&quo ...
- jquery 上滑加载更多
$(document).ready(function() { var totalPage = {$totalPage};//总页数 var page = {$page}; //起始页 var page ...
- APICloud 上滑加载更多
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> ...
- 微信小程序上滑加载更多
onReachBottom: function () { var that = this var limit = that.data.limit var count = that.data.count ...
- jq上滑加载更多
html 结构 <div id="main"> <ul class="order-list" id="list_box"& ...
随机推荐
- wxpy: 用 Python 玩微信【转】
转自:https://wxpy.readthedocs.io/zh/latest/index.html 微信机器人 / 可能是最优雅的微信个人号 API wxpy 在 itchat 的基础上,通过大量 ...
- MD5 与 SHA 在 Delphi 中函数实现,加密密码
MD5 与 SHA 在 Delphi 中函数实现. 为了加密密码,必须使用一种算法,查询资料,比较好的方法是使用:MD5等算法,参考:Delphi XE8 支持MD5 第一种方式是:引用 System ...
- 设计模式C++学习笔记之二(Proxy代理模式)
代理,一看名字就知道这只是个中介而已,真实的执行者在代理的后面呢.cbf4life在他的书里提的例子也很有趣,更详细的内容及说明可以参考原作者博客:cbf4life.cnblogs.com.现在贴 ...
- HTML5在线预览PDF
简介 PDF.js is a Portable Document Format (PDF) viewer that is built with HTML5. PDF.js is community-d ...
- $Django 中间件 csrf
中间件 -中间件是什么?请求和响应之间的一道屏障 -中间件作用:控制请求和响应 -django中内置几个中间件 process_request(self,request) proces ...
- [转]TSVNCache.exe卡死电脑的解决方法
转至于https://blog.csdn.net/gnail_oug/article/details/55506820. 正文如下: 每当打开explorer资源管理器的时候,经常卡死,换了固态硬盘还 ...
- ipfs上传下载
上传下载步骤: 启动ipfs节点服务器: 页面效果显示如下: 当在一个终端启动ipfs节点服务器之后之后,上传下载步骤: 1.创建文件demo4,新建一个文件a.txt,文本内容为hello mkdi ...
- bootstrap栅格系统中同行div高度不一致的解决方法
通过div底部的margin和padding实现,缺点:下边框无法完整显示,建议在无边框情况下使用 .row{ overflow: hidden; } [class*="col-" ...
- Ajax中onreadystatechange函数不执行,是因为放在open()后
今天动手写Ajax时遇到的问题:按照下面的顺序来写Ajax,功能是alert出txt文档的内容,在Chrome下可以执行onreadystatechange中的事件,在IE11及以下.FF就不能执行o ...
- windows 系统纯净版官网下载地址
http://www.imsdn.cn/operating-systems/windows-7/