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 ...
随机推荐
- 第一篇 SQL Server代理概述
本篇文章是SQL Server代理系列的第一篇,详细内容请参考原文. SQL Server代理是SQL Server的作业调度和告警服务,如果使用得当,它可以大大简化DBA的工作量.SQL Serve ...
- Linux 创建用户和工作组
创建用户 useradd user1 #创建user1用户,创建user1用户同时会创建一个同名的工作组user1 passwd user1 ...
- 查看iOS视图层级并修改UIsearchBar的cancel按钮不失去作用
(lldb) po [self.searchBar recursiveDescription] <UISearchBar: ; ); text = 'p'; opaque = NO; gestu ...
- 查看oracle数据库中的保留字
SQL> select * from v$reserved_words;
- 在Entity Framework 4.0中使用 Repository 和 Unit of Work 模式
[原文地址]Using Repository and Unit of Work patterns with Entity Framework 4.0 [原文发表日期] 16 June 09 04:08 ...
- Redis:安装
此篇文章并不介绍linux下安装方法.围绕windows安装而介绍 两种安装方式: 1)下载压缩包,解压后(运行起来有个窗口,关闭掉就不在运行),没有windows服务被注册:可以只用命令在cmd将其 ...
- IntelliJ IDEA 常用设置讲解2
IntelliJ IDEA 有很多人性化的设置我们必须单独拿出来讲解,也因为这些人性化的设置让我们这些 IntelliJ IDEA 死忠粉更加死心塌地使用它和分享它. 常用设置 如上图 Gif 所示, ...
- 源码安装zabbix
源码安装zabbix 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入:高级运维工程师之路 598432640 前言:参考网上多篇源码安装的连接,自己把安装过程丢在这 ...
- Facebook Hacker Cup 2014 Qualification Round
2014 Qualification Round Solutions 2013年11月25日下午 1:34 ...最简单的一题又有bug...自以为是真是很厉害! 1. Square Detector ...
- [转] java书籍(给Java程序猿们推荐一些值得一看的好书 + 7本免费的Java电子书和教程 )
7本免费的Java电子书和教程 1. Thinking in Java (Third Edition) 本书的作者是Bruce Eckel,它一直都是Java最畅销的免费电子书.这本书可以帮助你系统的 ...