JS 插件dropload下拉刷新、上拉加載使用小結(jié)
前端展示php代碼;
<?php
header("Content-type: text/html; charset=utf-8");
include_once("./config.php");
// 初始顯示界面數(shù)據(jù)獲取
$data = file_get_contents(URL."/interfaces/page.php?paging=1");
// echo $data;die;
$data = json_decode($data);
// var_dump($data);die;
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta name="viewport" content="initial-scale=1, user-scalable=0, minimal-ui" charset="UTF-8">
<title>加載頂部、底部</title>
<!-- 頁面布局 -->
<link rel="stylesheet" type="text/css" href="./css/display.css" rel="external nofollow" >
<!-- 框架布局 -->
<link rel="stylesheet" href="./css/dropload.css" rel="external nofollow" >
</head>
<body>
<div class="header">
<h1>就當(dāng)我是新聞頁吧</h1>
</div>
<div class="content">
<div class="lists">
<!-- lists在外 避免造成多次循環(huán)輸出 -->
<?php for ($i=0; $i < count($data->data) ; $i++) { ?>
<a class="item" href="#" rel="external nofollow" >
<img src="./img/pic.jpg" alt="">
<h3>hehe</h3>
<span class="date"><?php echo $data->data[$i]->id; ?></span>
</a>
<?php } ?>
</div>
</div>
<div class="footer">
<a href="#1" rel="external nofollow" class="item">測試菜單</a>
<a href="#2" rel="external nofollow" class="item">只做展示</a>
<a href="#3" rel="external nofollow" class="item">無功能</a>
<a href="#4" rel="external nofollow" class="item">不用點(diǎn)</a>
</div>
<!-- jQuery1.7以上 或者 Zepto 二選一,不要同時(shí)都引用 -->
<script src="./js/jquery.min.js"></script>
<script src="./js/dropload.min.js"></script>
<script>
$(function(){
var paging = 1;//頁碼數(shù)
// dropload函數(shù)接口設(shè)置
$('.content').dropload({
scrollArea : window,
// 下拉刷新模塊顯示內(nèi)容
domUp : {
domClass : 'dropload-up',
// 下拉過程顯示內(nèi)容
domRefresh : '<div class="dropload-refresh">↓下拉過程顯示內(nèi)容-下拉刷新-自定義內(nèi)容</div>',
// 下拉到一定程度顯示提示內(nèi)容
domUpdate : '<div class="dropload-update">↑釋放更新-自定義內(nèi)容</div>',
// 釋放后顯示內(nèi)容
domLoad : '<div class="dropload-load"><span class="loading"></span>加載中-自定義內(nèi)容...</div>'
},
domDown : {
domClass : 'dropload-down',
// 滑動(dòng)到底部顯示內(nèi)容
domRefresh : '<div class="dropload-refresh">↑上拉加載更多-自定義內(nèi)容</div>',
// 內(nèi)容加載過程中顯示內(nèi)容
domLoad : '<div class="dropload-load"><span class="loading"></span>加載中-自定義內(nèi)容...</div>',
// 沒有更多內(nèi)容-顯示提示
domNoData : '<div class="dropload-noData">暫無數(shù)據(jù)-自定義內(nèi)容</div>'
},
// 1 . 下拉刷新 回調(diào)函數(shù)
loadUpFn : function(me){
$.ajax({
type: 'GET',
// 每次獲取最新的數(shù)據(jù)即可
url: './interfaces/page.php?paging=1',
dataType: 'json',
success: function(data){
// $.ajax()雖然接口提供json字符串,但接收到的是 json對(duì)象
// alert(typeof(data));
var result = '';
// 循環(huán)拼接顯示內(nèi)容 DOM
// 刷新獲取多少數(shù)據(jù),顯示多少 使用html()重置 lists DOM
for(var i = 0; i < data.data.length; i++){
result += '<a class="item opacity" href="'+data.data[i].link+'" rel="external nofollow" rel="external nofollow" >'
+'<img src="'+data.data[i].pic+'" alt="">'
+'<h3>hehe</h3>'
+'<span class="date">'+data.data[i].id+'</span>'
+'</a>';
}
// 為了測試,延遲1秒加載
setTimeout(function(){
// 插入加載使用 html() 重置 DOM
$('.lists').html(result);
// 每次數(shù)據(jù)加載完,必須重置
me.resetload();
},1000);
},
// 加載出錯(cuò)
error: function(xhr, type){
alert('Ajax error!');
// 即使加載出錯(cuò),也得重置
me.resetload();
}
});
},
// 2 . 上拉加載更多 回調(diào)函數(shù)
loadDownFn : function(me){
paging++; // 每次請求,頁碼加1
$.ajax({
type: 'GET',
url: './interfaces/page.php?paging='+paging,
dataType: 'json',
success: function(data){
// data = JSON.parse(data);
var result = '';
// 選擇需要顯示的數(shù)據(jù) 拼接 DOM
for(var i = 0; i < data.data.length; i++){
result += '<a class="item opacity" href="'+data.data[i].link+'" rel="external nofollow" rel="external nofollow" >'
+'<img src="'+data.data[i].pic+'" alt="">'
+'<h3>heheh</h3>'
+'<span class="date">'+data.data[i].id+'</span>'
+'</a>';
if(data.data.length<15){
// 再往下已經(jīng)沒有數(shù)據(jù)
// 鎖定
me.lock();
// 顯示無數(shù)據(jù)
me.noData();
break;
}
}
// 為了測試,延遲1秒加載
setTimeout(function(){
// 加載 插入到原有 DOM 之后
$('.lists').append(result);
// 每次數(shù)據(jù)加載完,必須重置
me.resetload();
},1000);
},
// 加載出錯(cuò)
error: function(xhr, type){
alert('Ajax error!');
// 即使加載出錯(cuò),也得重置
me.resetload();
}
});
},
threshold : 50 // 什么作用???
});
});
</script>
</body>
</html>
后端分頁接口
<?php
header("Content-type: text/html; charset=utf-8");
// 包含數(shù)據(jù)庫配置信息
include_once('../config.php');
// 接收數(shù)據(jù)
$paging = isset($_REQUEST['paging'])?$_REQUEST['paging']:'';
// $paging = 1;
$num = 15;//每頁顯示記錄條數(shù)
$start_page = $num*($paging-1);// 每頁第一條記錄編號(hào)
// 用于返回?cái)?shù)據(jù)
$return = array();
$data = array();
/* mysqli 面向?qū)ο?編程方式 */
// 1 . 創(chuàng)建數(shù)據(jù)庫鏈接
$conn = new mysqli($servername,$username,$password,$database);
if ($conn->connect_error) {
die("連接失敗 : ".$conn->connect_error);
}
// echo "鏈接成功";
// 設(shè)置字符集(以防出錯(cuò) 每次都要寫)
$conn->query("SET NAMES utf8");
// 2 . 數(shù)據(jù)操作
$sql = "SELECT * FROM mission_news order by id desc limit $start_page , $num;";
// $sql = "SELECT * FROM mission_news order by id desc limit 0 , 15;";
// 3 . 執(zhí)行一條語句
$ret = $conn->query($sql);
// 4 . 循環(huán)獲取每條記錄
if ($ret->num_rows > 0) {
while ($row = $ret->fetch_assoc()) { //將每條記錄以 數(shù)組形式 返回
// var_dump($row);
// echo "id = ".$row['id']." mid = ".$row['mid']." context = ".$row['context']."<br>";
$tmp = array();//臨時(shí)數(shù)組整合信息
$tmp['id'] = $row['id'];
$tmp['mid'] = $row['mid'];
$tmp['context'] = $row['context'];
$tmp['turn'] = $row['turn'];
$tmp['created'] = $row['created'];
// 臨時(shí)數(shù)組 拼接到 返回的數(shù)組中
$data[] = $tmp; // 自增
}
// 拼接返回?cái)?shù)組
$return['result'] = 1;
$return['data'] = $data;
}
// 5 . 關(guān)閉數(shù)據(jù)庫
$conn->close();
// 6 . 編碼為json字符串返回
echo json_encode($return);
?>
以上所述是小編給大家介紹的JS 插件dropload下拉刷新、上拉加載使用小結(jié),希望對(duì)大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- vue插件mescroll.js實(shí)現(xiàn)移動(dòng)端上拉加載和下拉刷新
- vue.js整合vux中的上拉加載下拉刷新實(shí)例教程
- mescroll.js上拉加載下拉刷新組件使用詳解
- dropload.js插件下拉刷新和上拉加載使用詳解
- vue.js移動(dòng)端app之上拉加載以及下拉刷新實(shí)戰(zhàn)
- angularjs實(shí)現(xiàn)上拉加載和下拉刷新數(shù)據(jù)功能
- JS+CSS實(shí)現(xiàn)下拉刷新/上拉加載插件
- 基于iscroll.js實(shí)現(xiàn)下拉刷新和上拉加載效果
- 原生js實(shí)現(xiàn)下拉刷新和上拉加載更多
相關(guān)文章
BootstrapValidator不觸發(fā)校驗(yàn)的實(shí)現(xiàn)代碼
BootstrapValidator是基于bootstrap3的jquery表單驗(yàn)證插件,是最適合bootstrap框架的表單驗(yàn)證插件,本文給大家介紹BootstrapValidator不觸發(fā)校驗(yàn)的實(shí)現(xiàn)代碼,感興趣的朋友一起看看吧2016-09-09
點(diǎn)擊彈出層效果&彈出窗口后網(wǎng)頁背景變暗效果的實(shí)現(xiàn)代碼
本篇文章主要是對(duì)點(diǎn)擊彈出層效果&彈出窗口后網(wǎng)頁背景變暗效果的實(shí)現(xiàn)代碼進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助2014-02-02
響應(yīng)式框架Bootstrap柵格系統(tǒng)的實(shí)例
下面小編就為大家分享一篇響應(yīng)式框架Bootstrap柵格系統(tǒng)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2017-12-12
H5如何實(shí)現(xiàn)喚起APP及調(diào)試bug解決
這篇文章主要為大家介紹了H5如何實(shí)現(xiàn)喚起APP及調(diào)試bug解決,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
微信小程序?qū)崿F(xiàn)卡片左右滑動(dòng)效果的示例代碼
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)卡片左右滑動(dòng)效果的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05
Javascript自定義函數(shù)判斷網(wǎng)站訪問類型是PC還是移動(dòng)終端
如果,能夠判斷出訪問Web網(wǎng)頁的類型(PC還是移動(dòng)終端)。就可以解決許多絢麗多彩的 Flash效果出不來的問題2014-01-01

