欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

iscroll实现下拉刷新功能

程序员文章站 2022-05-26 08:30:35
本文实例为大家分享了android九宫格图片展示的具体代码,供大家参考,具体内容如下 版本号:iscroll4.2.5.js iscroll 版本很有关系 ...

本文实例为大家分享了android九宫格图片展示的具体代码,供大家参考,具体内容如下

版本号:iscroll4.2.5.js

iscroll 版本很有关系  在线: demo链接   有出现白屏的bug,将iscroll版本改成iscroll4.2.5就可以了

html

<!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 demo: simple</title>

<script type="text/javascript" src="../../src/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>

<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(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 id="header"><a href="http://cubiq.org/iscroll" rel="external nofollow" >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>

</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。