本文实例为大家分享了iScroll下拉刷新上滑加载展示的具体代码,供大家参考,具体内容如下
<div class="header">header
<div id="wrapper">
<div id="scroller">
<div id="pullDown">
<span class="pullDownLabel">下拉刷新
css代码:
js代码:
if (this.y > 5 && !pullDownEl.className.match('flip')) {
pullDownEl.className = 'flip';
pullDownEl.querySelector('.pullDownLabel').innerHTML = '释放刷新';
this.minScrollY = 0;
} else if (this.y < 5 && pullDownEl.className.match('flip')) {
pullDownEl.className = '';
pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';
this.minScrollY = -pullDownOffset;
} else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {
pullUpEl.className = 'flip';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '释放刷新';
this.maxScrollY = this.maxScrollY;
} else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {
pullUpEl.className = '';
pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';
this.maxScrollY = pullUpOffset;
}
},onScrollEnd: function () {
if (pullDownEl.className.match('flip')) {
pullDownEl.className = 'loading';
pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中';
pullDownAction(); // Execute custom function (ajax call?)
} else if (pullUpEl.className.match('flip')) {
pullUpEl.className = 'loading';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中';
pullUpAction(); // Execute custom function (ajax call?)
}
}
});
loadAction();
}
document.addEventListener('touchmove',function (e) { e.preventDefault(); },false);//阻止冒泡
document.addEventListener('DOMContentLoaded',function () { setTimeout(loaded,0); },false);
//初始状态,加载数据
function loadAction(){
var el,li;
el = document.getElementById('thelist');
for (i=0; i<10; i++) {
li = document.createElement('li');
li.innerText = '初始数据--' + (++generatedCount);
el.appendChild(li,el.childNodes[0]);
}
myScroll.refresh();
}
//下拉刷新当前数据
function pullDownAction () {
setTimeout(function () {
//这里执行刷新操作
myScroll.refresh();
},400);
}
//上拉加载更多数据
function pullUpAction () {
setTimeout(function () {
var el,li;
el = document.getElementById('thelist');
for (i=0; i<10; i++) {
li = document.createElement('li');
li.innerText = '上拉加载--' + (++generatedCount);
el.appendChild(li,el.childNodes[0]);
}
myScroll.refresh();
},400);
}
截图: