<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width=device-width,initial-scale=1.0,
maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="public/reset.css">
<style type="text/css">
.top{
    top: 0;
}
.footer{
    bottom: 0;
}
.top,.footer{
    position: fixed;
    left: 0;
    text-align: center;
    line-height: 50px;
    height: 50px;
    width: 100%;
    background-color: #0dcecb;
    color: #fff;
    z-index: 100;
}
#wrapper{
    position: absolute;
    left: 0;
    top: 50px;
    bottom: 50px;
    width: 100%;
    background-color: #fafafa;
    z-index: 10;
}
.news-lists .item{
    height: 40px;
    line-height: 40px;
    border-bottom: 1px solid #CFCFCF;
} #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(public/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); }
}
</style>
</head>
<body>
    <div class="top">
页面导航
</div>
<div id="wrapper">
<div id="scroller">
<div id="pullDown">
<span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新...</span>
</div>
<div class="news-lists" id="news-lists">
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
<div class="item">根据市场奖惩制度,结合市场各部门提供的数据</div>
</div>
<div id="pullUp">
<span class="pullUpIcon"></span><span class="pullUpLabel">上拉加载更多...</span>
</div>
</div>
</div>
<div class="footer">
底部导航
</div>
</body>
</html>
<script type="text/javascript" src="public/zepto.js"></script>
<script type="text/javascript" src="public/iscroll.js"></script>
<script type="text/javascript">     var data,
myScroll,
pullDownEl, pullDownOffset,
pullUpEl, pullUpOffset,
generatedCount = 0; function pullDownAction () {
$.getJSON('public/test.json', function (data, state) {
if (data && data.state == 1 && state == 'success') {
//本地测试,为了看到加载中效果故加上定时器
setTimeout(function () {
$('#news-lists').before(data.data);
myScroll.refresh();
}, 600);
}
});
} function pullUpAction () { $.getJSON('public/test.json', function (data, state) {
if (data && data.state == 1 && state == 'success') {
//本地测试,为了看到加载中效果故加上定时器
setTimeout(function () {
$('#news-lists').append(data.data);
myScroll.refresh();
}, 600);
}
});
} //去除浏览器默认事件
document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
//domready后绑定初始化事件
document.addEventListener('DOMContentLoaded', loaded, false); function loaded() {
pullDownEl = document.getElementById('pullDown');
pullDownOffset = pullDownEl.offsetHeight;
pullUpEl = document.getElementById('pullUp');
pullUpOffset = pullUpEl.offsetHeight; /**
 * 初始化iScroll控件
 */
myScroll = new iScroll('wrapper', {
vScrollbar : false,
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 = '松手开始更新...';
this.minScrollY = 0;
} else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {
pullUpEl.className = 'flip';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始更新...';
}
},
onScrollEnd: function () {
if (pullDownEl.className.match('flip')) {
pullDownEl.className = 'loading';
pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';
pullDownAction();
} else if (pullUpEl.className.match('flip')) {
pullUpEl.className = 'loading';
pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';
pullUpAction();
}
}
});
}
</script>

需要用移动端浏览器或google的debug模拟移动端浏览器

效果演示    源码下载

转自:http://my.oschina.net/felumanman/blog/478013

zepto.js + iscroll.js上拉加载 下拉加载的 移动端 新闻列表页面的更多相关文章

  1. iscroll.js实现上拉刷新,下拉加载更多,应用技巧项目实战

    上拉刷新,下拉加载更多...仿原生的效果----iscroll是一款做滚动效果的插件,具体介绍我就不废话,看官方文档,我只写下我项目开发的一些用到的用法: (如果不好使,调试你的css,想必是个很蛋疼 ...

  2. 微信小程序上拉加载下拉刷新

    微信小程序实现上拉加载下拉刷新 使用小程序默认提供方法. (1). 在xxx.json 中开启下拉刷新,需要设置backgroundColor,或者是backgroundTextStyle ,因为加载 ...

  3. Vue mint ui用在消息页面上拉加载下拉刷新loadmore 标记

    之前总结过一个页面存在多个下拉加载的处理方式,今天再来说一下在消息页面的上拉加载和下拉刷新,基本上每个app都会有消息页面,会遇到这个需求 需求:每次加载十条数据,上拉加载下拉刷新,并且没有点击查看过 ...

  4. PullToRefreshGridView上拉刷新,下拉加载

    PullToRefreshGridView上拉刷新,下拉加载 布局: <?xml version="1.0" encoding="utf-8"?> ...

  5. vux (scroller)上拉刷新、下拉加载更多

    1)比较关键的地方是要在 scroller 组件上里加一个 ref 属性 <scroller :lockX=true height="-170" :pulldown-conf ...

  6. iOS--MJRefresh的使用 上拉刷新和下拉加载

    1.一般使用MJRefresh 来实现上拉刷新和下拉加载功能 2.MJRefresh 下载地址:https://github.com/CoderMJLee/MJRefresh 3. MJRefresh ...

  7. 上拉加载下拉刷新控件WaterRefreshLoadMoreView

    上拉加载下拉刷新控件WaterRefreshLoadMoreView 效果: 源码: // // SRSlimeView // @author SR // Modified by JunHan on ...

  8. RecyclerView 上拉加载下拉刷新

    RecyclerView 上拉加载下拉刷新 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/teach_s ...

  9. APICloud上啦加载下拉刷新模块

    apicloud有自带的上啦加载下拉刷新,当让也可以用第三方或者在模块库里面找一个使用 一.下拉刷新,一下代码写在 apiready = function (){} 里面 apiready = fun ...

随机推荐

  1. 【未完待补充】linux 设置So动态库链接路径

    缘起 安装python的包Rtree(Rtree-0.8.2),但需要先安装C语言依赖包spatialindex-src(spatialindex-src-1.8.5).在安装完spatialinde ...

  2. SO_REUSEADDR

    问题:Linux的服务器程序,关闭后马上启动,经常报错,说是端口已经被占用,不过稍等一会儿就可以启动了. 原来我们在调用closesocket把已绑定端口的socket关闭时,这个socket并没有立 ...

  3. JSON Web Token

    What is JSON Web Token? JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact a ...

  4. Unable to get setting value Parameter name: profileName

    Today when I am building my application, everything works well but when I try to run Azure Worker Ro ...

  5. pptp建立vpn

    1. 安装依赖 ppp yum -y install ppp 2. 编译安装pptpd wget http://jaist.dl.sourceforge.net/project/poptop/pptp ...

  6. tcp/ip分片

    from http://blog.csdn.net/cumirror/article/details/5071234 前段时间要做一个关于网络嗅探的程序,里面要重组IP分片,TCP分片. 但做的时候忽 ...

  7. maven增加Spring

    对于javax.annotation,spring某些注解要用的,比如:@Resource.   使用Maven管理基本的Spring依赖关系 Spring被设计为可高度模块化的 —— 使用Sprin ...

  8. 转:python webdriver API 之鼠标事件

    前面例子中我们已经学习到可以用 click()来模拟鼠标的单击操作,而我们在实际的 web 产品测试中 发现,有关鼠标的操作,不单单只有单击,有时候还要和到右击,双击,拖动等操作,这些操作包含在Act ...

  9. 设置searchBar上右边取消按钮的颜色

    [[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:RGBA(0, 161, 176 ...

  10. HDU 1724 Ellipse(数值积分の辛普森公式)

    Problem Description Math is important!! Many students failed in 2+2’s mathematical test, so let's AC ...