zepto.js + iscroll.js上拉加载 下拉加载的 移动端 新闻列表页面
<!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上拉加载 下拉加载的 移动端 新闻列表页面的更多相关文章
- iscroll.js实现上拉刷新,下拉加载更多,应用技巧项目实战
上拉刷新,下拉加载更多...仿原生的效果----iscroll是一款做滚动效果的插件,具体介绍我就不废话,看官方文档,我只写下我项目开发的一些用到的用法: (如果不好使,调试你的css,想必是个很蛋疼 ...
- 微信小程序上拉加载下拉刷新
微信小程序实现上拉加载下拉刷新 使用小程序默认提供方法. (1). 在xxx.json 中开启下拉刷新,需要设置backgroundColor,或者是backgroundTextStyle ,因为加载 ...
- Vue mint ui用在消息页面上拉加载下拉刷新loadmore 标记
之前总结过一个页面存在多个下拉加载的处理方式,今天再来说一下在消息页面的上拉加载和下拉刷新,基本上每个app都会有消息页面,会遇到这个需求 需求:每次加载十条数据,上拉加载下拉刷新,并且没有点击查看过 ...
- PullToRefreshGridView上拉刷新,下拉加载
PullToRefreshGridView上拉刷新,下拉加载 布局: <?xml version="1.0" encoding="utf-8"?> ...
- vux (scroller)上拉刷新、下拉加载更多
1)比较关键的地方是要在 scroller 组件上里加一个 ref 属性 <scroller :lockX=true height="-170" :pulldown-conf ...
- iOS--MJRefresh的使用 上拉刷新和下拉加载
1.一般使用MJRefresh 来实现上拉刷新和下拉加载功能 2.MJRefresh 下载地址:https://github.com/CoderMJLee/MJRefresh 3. MJRefresh ...
- 上拉加载下拉刷新控件WaterRefreshLoadMoreView
上拉加载下拉刷新控件WaterRefreshLoadMoreView 效果: 源码: // // SRSlimeView // @author SR // Modified by JunHan on ...
- RecyclerView 上拉加载下拉刷新
RecyclerView 上拉加载下拉刷新 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/teach_s ...
- APICloud上啦加载下拉刷新模块
apicloud有自带的上啦加载下拉刷新,当让也可以用第三方或者在模块库里面找一个使用 一.下拉刷新,一下代码写在 apiready = function (){} 里面 apiready = fun ...
随机推荐
- android网络编程--从网络下载图片,并保存到内存卡
功能1:从网络上取得的图片显示到imageview上面,生成Bitmap时有两种方法,一种是先转换为byte[],再生成bitmap:一种是直接用InputStream生成bitmap.功能2:点击按 ...
- Maven 命令操作项目
1.创建一个多模块的Java项目 shift+鼠标右键 创建项目命令: 旧版: mvn archetype:create -DgroupId=com.qhong -DartifactId=MavenP ...
- VS2010 AlwaysCreate
VS2010 解决方案里有两个工程,每次按F7编译都会链接一次.链接完成再按F7又会链接一次..... 提示: 正在创建“Debug\testb.unsuccessfulbuild”,因为已指定“Al ...
- tableview head
http://stackoverflow.com/questions/18880341/why-is-there-extra-padding-at-the-top-of-my-uitableview- ...
- Make Rules
target: components ls TAB rule main:main.o mytool1.o mytool2.o gcc -o main main.o mytool1.o mytool2. ...
- sdutoj 2607 Mountain Subsequences
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2607 Mountain Subsequence ...
- [原创]java WEB学习笔记85:Hibernate学习之路-- -映射 一对一关系 ,基于主键方式实现
本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...
- javax.servlet.jsp.JspException cannot be resolved to a type
javax.servlet.jsp.PageContext cannot be resolved to a type javax.servlet.jsp.JspException cannot be ...
- linux第7天 I/O的五种模型, select
服务器端避免僵尸进程的方法: 1)通过忽略SIGCHLD信号,解决僵尸进程 signal(SIGCHLD, SIG_IGN) 2)通过wait方法,解决僵尸进程 signal(SIGCHLD, han ...
- MVC4 下DropDownList使用方法
与MVC3相比,差别很大: 表现形式一: public ActionResult Main() { List<SelectListItem> items = new List<Sel ...