html5+css3实现上拉和下拉刷新

<!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>html5+css3实现上拉和下拉刷新</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; z-index:2;      top:0; left:0;      width:100%;      height:45px;      line-height:45px;      background-color:#d51875;      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; z-index:2;      bottom:0; left:0;      width:100%;      height:48px;      background-color:#222;      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:-9999px;      width:100%;      background:#aaa;      overflow:auto;    }

    #scroller {      position:absolute; z-index:1;      /*    -webkit-touch-callout:none;*/      -webkit-tap-highlight-color:rgba(0,0,0,0);      width:100%;      padding:0;    }

    #scroller ul {      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;    }

    #myFrame {      position:absolute;      top:0; left:0;    }

    /**     *     * 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(http://statics.webkfa.com/img/[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);    }

    #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="http://cubiq.org/iscroll">iScroll</a></div><div id="wrapper">  <div id="scroller">    <div id="pullDown">      <span class="pullDownIcon"></span><span class="pullDownLabel">Pull down to refresh...</span>    </div>

    <ul id="thelist">      <li>Pretty row 1</li>      <li>Pretty row 2</li>      <li>Pretty row 3</li>      <li>Pretty row 4</li>      <li>Pretty row 5</li>      <li>Pretty row 6</li>      <li>Pretty row 7</li>      <li>Pretty row 8</li>      <li>Pretty row 9</li>      <li>Pretty row 10</li>      <li>Pretty row 11</li>      <li>Pretty row 12</li>      <li>Pretty row 13</li>      <li>Pretty row 14</li>      <li>Pretty row 15</li>      <li>Pretty row 16</li>      <li>Pretty row 17</li>      <li>Pretty row 18</li>      <li>Pretty row 19</li>      <li>Pretty row 20</li>      <li>Pretty row 21</li>      <li>Pretty row 22</li>      <li>Pretty row 23</li>      <li>Pretty row 24</li>      <li>Pretty row 25</li>      <li>Pretty row 26</li>      <li>Pretty row 27</li>      <li>Pretty row 28</li>      <li>Pretty row 29</li>      <li>Pretty row 30</li>      <li>Pretty row 31</li>      <li>Pretty row 32</li>      <li>Pretty row 33</li>      <li>Pretty row 34</li>      <li>Pretty row 35</li>      <li>Pretty row 36</li>      <li>Pretty row 37</li>      <li>Pretty row 38</li>      <li>Pretty row 39</li>      <li>Pretty row 40</li>    </ul>    <div id="pullUp">      <span class="pullUpIcon"></span><span class="pullUpLabel">Pull up to refresh...</span>    </div>  </div></div><div id="footer"></div><script type="text/javascript" src="/static/js/iscroll.js"></script>

<script type="text/javascript">

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

  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 = ‘Generated row ‘ + (++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!  }

  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 = ‘Generated row ‘ + (++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!  }

  function loaded() {    pullDownEl = document.getElementById(‘pullDown‘);    pullDownOffset = pullDownEl.offsetHeight;    pullUpEl = document.getElementById(‘pullUp‘);    pullUpOffset = pullUpEl.offsetHeight;

    myScroll = new iScroll(‘wrapper‘, {      useTransition: true,      topOffset: pullDownOffset,      onRefresh: function () {        if (pullDownEl.className.match(‘loading‘)) {          pullDownEl.className = ‘‘;          pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Pull down to refresh...‘;        } else if (pullUpEl.className.match(‘loading‘)) {          pullUpEl.className = ‘‘;          pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Pull up to load more...‘;        }      },      onScrollMove: function () {        if (this.y > 5 && !pullDownEl.className.match(‘flip‘)) {          pullDownEl.className = ‘flip‘;          pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Release to refresh...‘;          this.minScrollY = 0;        } else if (this.y < 5 && pullDownEl.className.match(‘flip‘)) {          pullDownEl.className = ‘‘;          pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Pull down to refresh...‘;          this.minScrollY = -pullDownOffset;        } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match(‘flip‘)) {          pullUpEl.className = ‘flip‘;          pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Release to refresh...‘;          this.maxScrollY = this.maxScrollY;        } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match(‘flip‘)) {          pullUpEl.className = ‘‘;          pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Pull up to load more...‘;          this.maxScrollY = pullUpOffset;        }      },      onScrollEnd: function () {        if (pullDownEl.className.match(‘flip‘)) {          pullDownEl.className = ‘loading‘;          pullDownEl.querySelector(‘.pullDownLabel‘).innerHTML = ‘Loading...‘;          pullDownAction();    // Execute custom function (ajax call?)        } else if (pullUpEl.className.match(‘flip‘)) {          pullUpEl.className = ‘loading‘;          pullUpEl.querySelector(‘.pullUpLabel‘).innerHTML = ‘Loading...‘;          pullUpAction();    // Execute custom function (ajax call?)        }      }    });

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

  document.addEventListener(‘touchmove‘, function (e) { e.preventDefault(); }, false);

  document.addEventListener(‘DOMContentLoaded‘, function () { setTimeout(loaded, 200); }, false);</script></body></html>
时间: 2024-11-10 00:05:54

html5+css3实现上拉和下拉刷新的相关文章

html5+css3实现手机下拉和下拉刷新

<!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-

CSS3实现的横向二级下拉菜单代码实例

CSS3实现的横向二级下拉菜单代码实例:横向二级下拉菜单是非常常用的效果,例如很多网站的导航栏就是这样的二级下拉菜单效果,非常好用,本章节分享一段使用CSS3实现的下拉菜单,当然当下很多浏览器都不支持,不过相信用不了多久这种现状就会被改变.代码实例如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content

CSS3蓝色宽屏二级下拉菜单DEMO演示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="viewport"

纯CSS3实现宽屏二级下拉菜单

今天我们要来分享一款基于纯CSS3的宽屏二级下拉菜单,这款菜单的子菜单在展开的时候是很宽敞的,菜单项中可以自定义格式的内容,非常实用,也很大气.由于是用纯CSS3实现,所以这款下拉菜单不用运行Javascript,展示速度当然是非常快的. 在线预览   源码下载

使用iScroll实现上拉或者下拉刷新

上拉或者下拉刷新的需求在移动端是非常常见的需求,大部分情况下,实现这个效果都使用网上现有的解决方案,例如有人使用swiper这个插件, 也有人使用iScroll这个滚动插件.本文的示例是利用iscroll实现的下拉刷新效果. iScroll简介 iScrool是目前最成熟的自定义滚动解决方案之一,在移动端和PC有很好的兼容性.iScroll官方提供了5个不同的版本: iscroll.js 通用版 包含了大部分公共特性 iscroll-lite.js 缩减版 削减了一些功能特性,例如:滚动条,鼠标

ListView装上拉电阻下拉刷新

主要用到了这个几个文件.MainActivity是界面的Activity,MyAdapter是ListView的自己定义适配,MyListView是自己定义带头部LIistView,假设仅仅须要上拉载入就不须要:activity_main.xml是住界面.item.xml是ListView的子布局里面仅仅有一个TextView,listview_footer.xml是listview的载入很多其它的底部布局,listview_header.xml是listview的头部布局. MainActiv

TableView上拉、下拉原理

TableView的上拉,下拉特效已经满大街都是了,也有很多第三方的代码. 这两天研究了一下其原理,分享一下思路.这里以tableView的上拉为例,由于上拉操作的样式也很多,这里只介绍一种:在上拉tableView的时候,在tableView的bottom下面,添加一个view,该view可以自定义.我称这个view为pullView,pullView是动态的,如下图(该图仅展示了loading状态,另外在loading的位置,还有"上拉显示更多"."松手显示更多"

Android新控件RecyclerView浅析及上拉和下拉刷新

概述: RecyclerView是android-support-v7-21版本中新增的一个Widgets,RecyclerView是ListView的升级版本,更加先进和灵活.在以后的开发中我们就可以直接使用RecyclerView来替换ListView. 特点介绍: 1. 可横向展示 2. 消除错位问题 3. 标准化了ViewHolder 横向: private void initHorizaontal(List<ItemModel> models) { RecyclerView recy

#Java Web累积#关于MUI的上滑和下拉加载

其实按照MUI的文档去写,也没什么问题: JSP中: <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html><head> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scal