使用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"& ...
随机推荐
- HTTP协议03-http特点及请求方式
无状态: HTTP是一种不保存状态,既无状态协议.HTTP自身不对请求和响应之间的通信状态进行保存,也就是说不做持久化处理.这是为了更快处理大量事务,确保协议的可伸缩性. 随着web的不断发展,无状态 ...
- 转换简体中文和繁体中文 cconv-0.6.2 for win32 static
dos状态下 chcp 65001 echo "转换简体中文和繁体中文"|cconv -f utf-8 -t utf8-tw 显示 "轉換簡體中文和繁體中文" ...
- 微信小程序-WebSocket应用
为何有 HTTP 协议还需要 WebSocket ? Http协议 有个缺陷:通信只能由客户端发起.举例来说,我们想了解今天的天气,只能是客户端向服务器发出请求,服务器返回查询结果.HTTP 协议做不 ...
- 007_Chrome的Waterfall详解
一. 浏览器根据html中外连资源出现的顺序,依次放入队列(Queue),然后根据优先级确定向服务器获取资源的顺序.同优先级的资源根据html中出现的先后顺序来向服务器获取资源 Queueing. 出 ...
- InnoDB 与 MYISAM的区别和联系
1.存储引擎是什么? MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力.通过选择不同的技术, ...
- 【原创】大数据基础之Logstash(1)简介、安装、使用
Logstash 6.6.2 官方:https://www.elastic.co/products/logstash 一 简介 Centralize, Transform & Stash Yo ...
- 【原创】运维基础之OpenResty(Nginx+Lua)+Kafka
使用docker部署 1 下载 # wget https://github.com/doujiang24/lua-resty-kafka/archive/v0.06.tar.gz# tar xvf v ...
- python-并发编程之多进程
一.操作系统基础: 进程的概念起源于操作系统,操作系统其它所有概念都是围绕进程来的,所以我们了解进程之前先来了解一下操作系统 操作系统位于计算机硬件与应用软件之间,本质也是一个软件.操作系统由操作系统 ...
- hibernate入门程序
快速入门 1. 下载Hibernate框架的开发包 2. 编写数据库和表结构 Create database hibernate_day01; Use hibernate_da ...
- Confluence 6 数据库整合的限制
数据库整合的限制 注意: Confluence 自带的 XML 方式导出方法并不适用于备份和整合大数据集.这里有一些第三方的数据库工具你可以使用能够帮助你对大数据集进行备份和整合.如果你在选择正确工具 ...