收藏 分销(赏)

iscroll上拉下滑加载数据.doc

上传人:仙人****88 文档编号:12013089 上传时间:2025-08-27 格式:DOC 页数:13 大小:82.50KB 下载积分:10 金币
下载 相关 举报
iscroll上拉下滑加载数据.doc_第1页
第1页 / 共13页
iscroll上拉下滑加载数据.doc_第2页
第2页 / 共13页


点击查看更多>>
资源描述
第一步:页面展示第一页数据 <div id="wrapper"> <div id="scroller" class="food_d"> <div id="pullDown"> <span class="pullDownIcon"></span><span class="pullDownLabel" style="display: block;">向下滑动刷新...</span> </div> <ul id="foodUl"> <c:forEach var="cate" items="${list }" > ${cate.goodstitle } </c:forEach> </ul> <div id="pullUp" style="width:100%;float:left;"> <span class="pullUpIcon"></span><span class="pullUpLabel" style="margin-top:-40px; height: 30px; float:left; width: 100%; text-align: center;">向上滑动加载更多...</span> </div> </div> </div> 第二部: <script type="text/javascript" src="<%=path %>/js/iscroll.js"></script> 第三部: /* 滑动 */ #wrapper { position:absolute; z-index:1; top:45px; bottom:48px; left:auto; width:100%; overflow:auto; } #myFrame { position:absolute; top:0; left:0; } /** * * Pull down styles * */ #pullDown, #pullUp { background:#fff; height:40px; line-height:40px; padding:5px 10px; border-bottom:1px solid #ccc; font-weight:bold; font-size:14px; color:#888; } #pullDown .pullDownIcon, #pullUp .pullUpIcon { display:block; float:left; width:40px; height:40px; background:url(pull-icon@2x.png) 0 0 no-repeat; -webkit-background-size:40px 80px; background-size:40px 80px; -webkit-transition-property:-webkit-transform; -webkit-transition-duration:250ms; } #pullDown .pullDownIcon { -webkit-transform:rotate(0deg) translateZ(0); } #pullUp .pullUpIcon { -webkit-transform:rotate(-180deg) translateZ(0); } #pullDown.flip .pullDownIcon { -webkit-transform:rotate(-180deg) translateZ(0); } #pullUp.flip .pullUpIcon { -webkit-transform:rotate(0deg) translateZ(0); } #pullDown.loading .pullDownIcon, #pullUp.loading .pullUpIcon { background-position:0 100%; -webkit-transform:rotate(0deg) translateZ(0); -webkit-transition-duration:0ms; -webkit-animation-name:loading; -webkit-animation-duration:2s; -webkit-animation-iteration-count:infinite; -webkit-animation-timing-function:linear; } @-webkit-keyframes loading { from { -webkit-transform:rotate(0deg) translateZ(0); } to { -webkit-transform:rotate(360deg) translateZ(0); } } 第四部: var myScroll, pullDownEl, pullDownOffset, pullUpEl, pullUpOffset, generatedCount = 0; //计算pageSize var pageSize = 0; //初始化 $(document).ready(function() { $(".rating-kv").rating(); pageSize = $("#pageSize").val(); loaded(); document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false); document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false); }); //加载 function loaded() { pullDownEl = document.getElementById('pullDown'); pullDownOffset = pullDownEl.offsetHeight; pullUpEl = document.getElementById('pullUp'); pullUpOffset = pullUpEl.offsetHeight; myScroll = new iScroll('wrapper', { useTransition: true, topOffset: pullDownOffset, onRefresh: function () { if (pullDownEl.className.match('loading')) { pullDownEl.className = ''; pullDownEl.querySelector('.pullDownLabel').innerHTML = '向下滑动刷新...'; } else if (pullUpEl.className.match('loading')) { pullUpEl.className = ''; pullUpEl.querySelector('.pullUpLabel').innerHTML = '向上滑动加载更多...'; } }, onScrollMove: function () { if (this.y > 5 && !pullDownEl.className.match('flip')) { pullDownEl.className = 'flip'; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Release to refresh...'; this.minScrollY = 0; } else if (this.y < 5 && pullDownEl.className.match('flip')) { pullDownEl.className = ''; pullDownEl.querySelector('.pullDownLabel').innerHTML = '向下滑动刷新...'; this.minScrollY = -pullDownOffset; } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) { pullUpEl.className = 'flip'; pullUpEl.querySelector('.pullUpLabel').innerHTML = '松开...'; this.y = this.maxScrollY; } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) { pullUpEl.className = ''; pullUpEl.querySelector('.pullUpLabel').innerHTML = '向上滑动加载更多...'; this.maxScrollY = pullUpOffset; } }, onScrollEnd: function () { if (pullDownEl.className.match('flip')) { pullDownEl.className = 'loading'; pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Loading...'; pullDownAction(); // Execute custom function (ajax call?) } else if (pullUpEl.className.match('flip')) { pullUpEl.className = 'loading'; pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Loading...'; pullUpAction(); // Execute custom function (ajax call?) } } }); setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 800); } //向下滑动 function pullDownAction () { setTimeout(function () { // <-- Simulate network congestion, remove setTimeout from production! $.ajax({ type:"post", url: , data:downObj, success:function(iRet){ var ct= (new Function("", "return " + iRet))(); if(null != iRet && "" != iRet && null != ct){ //先清空ul $("#foodUl").html(""); //append拼接下一页数据 } } }); myScroll.refresh(); // Remember to refresh when contents are loaded (ie: on ajax completion) }, 1000); // <-- Simulate network congestion, remove setTimeout from production! } //向上滑动 function pullUpAction () { setTimeout(function () { // <-- Simulate network congestion, remove setTimeout from production! //计算起始条数 var tonum = parseInt($("#tonum").val()) + parseInt(pageSize); $("#fromnum").val(parseInt($("#tonum").val()) + parseInt(1)); $("#tonum").val(tonum); $.ajax({ type:"post", url: , data:upObj, success:function(iRet){ var ct= (new Function("", "return " + iRet))(); if(null != ct){ //append拼接下一页数据 }else{ var tnum = parseInt($("#fromnum").val()) - parseInt(pageSize); $("#tonum").val(parseInt($("#fromnum").val())- parseInt(1)); $("#fromnum").val(tnum); $(".pullUpLabel").html("无更多数据"); } } }); myScroll.refresh(); // Remember to refresh when contents are loaded (ie: on ajax completion) }, 1000); // <-- Simulate network congestion, remove setTimeout from production! }
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 包罗万象 > 大杂烩

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服