JS 插件dropload下拉刷新、上拉加載使用小結(jié)
更新時(shí)間:2017年04月13日 14:26:04 投稿:mrr
這篇文章主要介紹了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>
<!-- 頁(yè)面布局 -->
<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)我是新聞頁(yè)吧</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">測(cè)試菜單</a>
<a href="#2" rel="external nofollow" class="item">只做展示</a>
<a href="#3" rel="external nofollow" class="item">無(wú)功能</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;//頁(yè)碼數(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">暫無(wú)數(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>';
}
// 為了測(cè)試,延遲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++; // 每次請(qǐng)求,頁(yè)碼加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();
// 顯示無(wú)數(shù)據(jù)
me.noData();
break;
}
}
// 為了測(cè)試,延遲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>
后端分頁(yè)接口
<?php
header("Content-type: text/html; charset=utf-8");
// 包含數(shù)據(jù)庫(kù)配置信息
include_once('../config.php');
// 接收數(shù)據(jù)
$paging = isset($_REQUEST['paging'])?$_REQUEST['paging']:'';
// $paging = 1;
$num = 15;//每頁(yè)顯示記錄條數(shù)
$start_page = $num*($paging-1);// 每頁(yè)第一條記錄編號(hào)
// 用于返回?cái)?shù)據(jù)
$return = array();
$data = array();
/* mysqli 面向?qū)ο?編程方式 */
// 1 . 創(chuàng)建數(shù)據(jù)庫(kù)鏈接
$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í)行一條語(yǔ)句
$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ù)庫(kù)
$conn->close();
// 6 . 編碼為json字符串返回
echo json_encode($return);
?>
以上所述是小編給大家介紹的JS 插件dropload下拉刷新、上拉加載使用小結(jié),希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(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)文章
javascript之學(xué)會(huì)吝嗇 精簡(jiǎn)代碼
前端開發(fā),要學(xué)會(huì)吝嗇:2010-04-04
實(shí)現(xiàn)JavaScript中數(shù)據(jù)響應(yīng)的方法總結(jié)
JavaScript 數(shù)據(jù)響應(yīng)是一種重要的前端開發(fā)概念,是指在應(yīng)用程序中的數(shù)據(jù)發(fā)生變化時(shí),能夠自動(dòng)更新與這些數(shù)據(jù)相關(guān)的用戶界面(UI)部分的能力,本文我們來(lái)總結(jié)一下目前可以簡(jiǎn)單實(shí)現(xiàn) JavaScript 中的數(shù)據(jù)響應(yīng)的方法,需要的朋友可以參考下2023-09-09
微信小程序如何加載數(shù)據(jù)庫(kù)真實(shí)數(shù)據(jù)的實(shí)現(xiàn)
這篇文章主要介紹了微信小程序如何加載數(shù)據(jù)庫(kù)真實(shí)數(shù)據(jù)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
JS實(shí)現(xiàn)的簡(jiǎn)潔縱向滑動(dòng)菜單(滑動(dòng)門)效果
這篇文章主要介紹了JS實(shí)現(xiàn)的簡(jiǎn)潔縱向滑動(dòng)菜單(滑動(dòng)門)效果,通過簡(jiǎn)單的頁(yè)面元素遍歷實(shí)現(xiàn)華東切換的功能,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10

