isscroll插件 实现下拉加载 上啦刷新 转

http://www.jb51.net/article/98394.htm

下面是别人的代码

<!DOCTYPE html>
<html>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
 <meta name="apple-mobile-web-app-capable" content="yes">
 <meta name="apple-mobile-web-app-status-bar-style" content="black">
 <title>iScroll 实例:下拉刷新,滚动翻页</title>
 <style type="text/css" media="all">
  body,ul,li {
   padding:0;
   margin:0;
   border:0;
  }

  body {
   font-size:12px;
   -webkit-user-select:none;
   -webkit-text-size-adjust:none;
   font-family:helvetica;
  }

  #header {
   position:absolute;
   top:0; left:0;
   width:100%;
   height:45px;
   line-height:45px;
   background-image:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #fe96c9), color-stop(0.05, #d51875), color-stop(1, #7b0a2e));
   background-image:-moz-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
   background-image:-o-linear-gradient(top, #fe96c9, #d51875 5%, #7b0a2e);
   padding:0;
   color:#eee;
   font-size:20px;
   text-align:center;
  }

  #header a {
   color:#f3f3f3;
   text-decoration:none;
   font-weight:bold;
   text-shadow:0 -1px 0 rgba(0,0,0,0.5);
  }

  #footer {
   position:absolute;
   bottom:0; left:0;
   width:100%;
   height:48px;
   background-image:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0, #999), color-stop(0.02, #666), color-stop(1, #222));
   background-image:-moz-linear-gradient(top, #999, #666 2%, #222);
   background-image:-o-linear-gradient(top, #999, #666 2%, #222);
   padding:0;
   border-top:1px solid #444;
  }

  #wrapper {
   position:absolute; z-index:1;
   top:45px; bottom:48px; left:0;
   width:100%;
   background:#555;
   overflow:auto;
  }

  #scroller {
   position:relative;
  /* -webkit-touch-callout:none;*/
   -webkit-tap-highlight-color:rgba(0,0,0,0);

   float:left;
   width:100%;
   padding:0;
  }

  #scroller ul {
   position:relative;
   list-style:none;
   padding:0;
   margin:0;
   width:100%;
   text-align:left;
  }

  #scroller li {
   padding:0 10px;
   height:40px;
   line-height:40px;
   border-bottom:1px solid #ccc;
   border-top:1px solid #fff;
   background-color:#fafafa;
   font-size:14px;
  }

  #scroller li > a {
   display:block;
  }

  /**
   *
   * 下拉样式 Pull down styles
   *
   */
  #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(pull[email protected]) 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);
  }

  /**
   * 动画效果css3代码
   */
  #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 id="header">
  <a href="../db.html#page2">iScroll实例:下拉刷新,滚动翻页</a>
 </div>

 <div id="wrapper">
  <div id="scroller">

   <div id="pullDown">
    <span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新...</span>
   </div>

   <ul id="thelist">
    <li>我是三冰 1</li>
    <li>我是三冰 2</li>
    <li>我是三冰 3</li>
    <li>我是三冰 4</li>
    <li>我是三冰 5</li>
    <li>我是三冰 6</li>
    <li>我是三冰 7</li>
    <li>我是三冰 8</li>
    <li>我是三冰 9</li>
    <li>我是三冰 10</li>
    <li>我是三冰 11</li>
    <li>我是三冰 12</li>
    <li>我是三冰 13</li>
   </ul>

   <div id="pullUp">
    <span class="pullUpIcon"></span><span class="pullUpLabel">上拉加载更多...</span>
   </div>

  </div>
 </div>

 <div id="footer"></div>
 /**引入iscroll插件**/
<script type="application/javascript" src="iscroll.js"></script>

<script type="text/javascript">

var myScroll,
 pullDownEl, pullDownOffset,
 pullUpEl, pullUpOffset,
 generatedCount = 0;

/**
 * 下拉刷新 (自定义实现此方法)
 * myScroll.refresh();  // 数据加载完成后,调用界面更新方法
 */
function pullDownAction () {
 setTimeout(function () { // <-- Simulate network congestion, remove setTimeout from production!
  var el, li, i;
  el = document.getElementById(‘thelist‘);

  for (i=0; i<3; i++) {
   li = document.createElement(‘li‘);
   li.innerText = ‘添加三冰 ‘ + (++generatedCount);
   el.insertBefore(li, el.childNodes[0]);
  }

  myScroll.refresh();  //数据加载完成后,调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
 }, 1000); // <-- Simulate network congestion, remove setTimeout from production!
}

/**
 * 滚动翻页 (自定义实现此方法)
 * myScroll.refresh();  // 数据加载完成后,调用界面更新方法
 */
function pullUpAction () {
 setTimeout(function () { // <-- Simulate network congestion, remove setTimeout from production!
  var el, li, i;
  el = document.getElementById(‘thelist‘);

  for (i=0; i<3; i++) {
   li = document.createElement(‘li‘);
   li.innerText = ‘添加三冰 ‘ + (++generatedCount);
   el.appendChild(li, el.childNodes[0]);
  }

  myScroll.refresh();  // 数据加载完成后,调用界面更新方法 Remember to refresh when contents are loaded (ie: on ajax completion)
 }, 1000); // <-- Simulate network congestion, remove setTimeout from production!
}

/**
 * 初始化iScroll控件
 */
function loaded() {
 pullDownEl = document.getElementById(‘pullDown‘);
 pullDownOffset = pullDownEl.offsetHeight;
 pullUpEl = document.getElementById(‘pullUp‘);
 pullUpOffset = pullUpEl.offsetHeight;

 myScroll = new iScroll(‘wrapper‘, {
  scrollbarClass: ‘myScrollbar‘, /* 重要样式 */
  useTransition: false, /* 此属性不知用意,本人从true改为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 < 5 && pullDownEl.className.match(‘flip‘)) {
    pullDownEl.className = ‘‘;
    pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘下拉刷新...‘;
    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 = ‘上拉加载更多...‘;
    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?)
   }
  }
 });

 setTimeout(function () { document.getElementById(‘wrapper‘).style.left = ‘0‘; }, 800);
}

//初始化绑定iScroll控件
document.addEventListener(‘touchmove‘, function (e) { e.preventDefault(); }, false);
document.addEventListener(‘DOMContentLoaded‘, loaded, false);

</script>
</body>
</html>
时间: 2024-10-11 04:44:22

isscroll插件 实现下拉加载 上啦刷新 转的相关文章

不依赖任何插件的下拉加载

HTML: 1 <ul id="loading"> 2 <li> 3 ... 4 </li> 5 </ul> 6 <div class="pullUpLabel"> 7 <span>点击加载</span> 8 </div> 其中ul#loading为容器. CSS: /*下拉加载*/ .pullUpLabel { text-align: center; line-heig

listview上拉加载上一页 下拉加载下一页共通处理

先什么都不说了,上效果图: 第一页默认显示: 上拉加载下一页: 拉至一定高度: 松开 加载中: 下拉加载上一页: 下拉至一定高度: 松开 加载中: 代码已经上传:http://download.csdn.net/detail/zengchao2013/8837971 共通的header和footer可以直接使用. 需要传入的三个参数:是否是第一页,是否是最后一页,当前页数 用于header和footer的UI显示,第一页header隐藏,最后一页footer隐藏.

关于MJRefresh的下拉加载数据bug

当没有更多数据的时候显示NoMoreData 我的理解是先结束刷新再显示没有更多 今天之前一直没发现有问题 贴之前的代码 [self.collectionView reloadData]; [self.collectionView.mj_header endRefreshing]; // 结束刷新 [self.collectionView.mj_footer endRefreshing]; NSArray *arr = data[@"Json"]; if (arr.count == 0

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

上拉刷新,下拉加载更多...仿原生的效果----iscroll是一款做滚动效果的插件,具体介绍我就不废话,看官方文档,我只写下我项目开发的一些用到的用法: (如果不好使,调试你的css,想必是个很蛋疼的问题,给点提示 :#wrapper,以及#scroller-content要注意) html如下: <div class="viewport"> <div id="wrapper" class="wrapper"> <

MUI实现上拉刷新和下拉加载

  前  言 ha ha 为实现下拉刷新功能,大多H5框架都是通过DIV模拟下拉回弹动画,在低端android手机上,DIV动画经常出现卡顿现象(特别是图文列表的情况): mui通过双webview解决这个DIV的拖动流畅度问题:拖动时,拖动的不是div,而是一个完整的webview(子webview),回弹动画使用原生动画. mui的上拉加载和下拉刷新类似,都属于pullRefresh插件. 上拉刷新 主页面内容比较简单,只需要创建子页面即可: mui.init({ subpages:[{ u

安卓,采用最简单易懂的方式实现上拉刷新下拉加载更多

<!-- Description:上拉刷新,下拉加载更多是现在最流行的手势操作,但是对于初学者来说,在实现上是有一定难度的, 网上很多教程讲的都过于复杂,对于初学者无法起到引导作用,特此写本文,帮助安卓新手入门理解此, 还有最为重要的一点:本文只帮助你理解,并不是想你成为代码搬运工!别被那么多代码吓到了, 其中很多都是注释,仔细看注释对你理解有很大的帮助 Author:Booker L Date:2014-05-16 --> 一,事先准备: 实现该功能,最基本的需要两个东西,一个是OnTouc

上拉刷新,下拉加载

#import "AppDelegate.h" #import "MyTableViewController.h" @interfaceAppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.win

Android之 RecyclerView,CardView 详解和相对应的上拉刷新下拉加载

随着 Google 推出了全新的设计语言 Material Design,还迎来了新的 Android 支持库 v7,其中就包含了 Material Design 设计语言中关于 Card 卡片概念的实现 -- CardView.RecyclerView也是谷歌V7包下新增的控件,用来替代ListView的使用,在RecyclerView标准化了ViewHolder类似于ListView中convertView用来做视图缓存. RecyclerView的优点就是,他可以通过设置LayoutMan

jQuery手机端上拉刷新下拉加载更多页面

<!doctype html> <html> <head> <title>jquery 手机端上拉刷新下拉加载更多页面</title> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <meta name="viewpost" content="width=device-wi