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 ...
随机推荐
- MEF 松耦合
MEF天生就有解耦合的特性,虽然它不是为解耦而生,而主要是为插件类应用的开发而设计.如果主要是为了解除耦合的话可以使用IoC,Unity等. Unity 微软的IOC 代码: using System ...
- .Net内存优化的几点经验
以前从来没有想过.Net开发居然存在内存无法释放的问题,总是认为GC给我处理好了一切.现在GIS二次开发结合三维球开发,没有想到存在如此严重的内存增长,很快内存就不够用了,导致系统各种不稳定.球体和三 ...
- os模块 关于路径问题使用
os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当于shell下cd os.curd ...
- iOS UICollectionView之三(基本用法)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- openId 列表
http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html 根据OpenID列表群发[订阅号不可用,服务号认证后可用] ...
- 这是我定位的Bug
https://github.com/danielgindi/ios-charts/issues/406
- Oracle Flashback Technologies - 闪回数据库
Oracle Flashback Technologies - 闪回数据库 根据指定的SCN,使用rman闪回数据库 #查看可以闪回到多久前 SQL> select * from v$flash ...
- linux:ACL权限
ACL权限是为了防止权限不够用的情况,一般的权限有所有者.所属组.其他人这三种,当这三种满足不了我们的需求的时候就可以使用ACL权限: 比如:一个网络老师,给一个班的学员上课,他在linux的根目录下 ...
- Leetcode: Elimination Game
There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number ...
- html 圆角边框
<input style="border-radius: 10px;" type="submit" value="确认"> bo ...