简易下拉刷新

css样式:

                         *{
margin: 0px;
padding: 0px; }
#wrapper{
width: 100%;
height: 150px;
border: 1px solid red;
overflow: hidden;
position: absolute;
}
#shua{
text-align: center;
}

HTML代码

             <div id="wrapper">
<div>
<div id="shua">刷新</div>
<ul>
<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>
</ul>
</div>
</div>

在写js代码之前,要引入jQuery插件和 iscroll插件

然后js代码如下:      <script type="text/javascript">

         //给内容添加滚动事件
var a=new IScroll("#wrapper",{
scrollbars:true,
mouseWheel:true,
interactiveScrollbars:true,
// scrollX:true,
// freeScroll:true,
probeType:2,
})
         //让文字先隐藏
$("#shua").hide();
var x=0;
a.on("scroll",function(){
if(x==0){
if(this.y>40){
$("#shua").show();
$("#shua").text("松开手进行刷新")
x=1;
}
a.on("scrollEnd",function(){
if(x==1){
$("#shua").text("正在刷新")
setTimeout(shuju,1000)
x=2;
}
})
var z=0;
function shuju(){
if(x==2){
$("#shua").hide();
$("ul>li:nth-child(1)").before($("<li></li>").text("数据"+ z++))
a.refresh()
x=0;
} }
} })
</script>

这样就完成了一个简单的下拉刷新!!

最新文章

  1. linux jexus 服务 设置开机启动
  2. Uiautomator 2.0之BySelector类学习小记
  3. Windows Azure Storage图形界面管理工具
  4. Study on Algorithm of Selecting Safe Landing Area on Ground During Asteroid Soft Landing (EEIC2013 +161)
  5. IPv4&amp;IPv6双重协议栈
  6. VsFTP+本地文件认证+SSl实现虚拟用户配置
  7. Oracle 事务相关的一些测试
  8. 解决IE11不能进行webTest脚本录制的方法
  9. 转载:修改xshell中文乱码的问题(管用)
  10. 第39篇 免费博客github Pages绑定域名
  11. Linux发行版 CentOS6.5 修改默认主机名
  12. select选中获取索引三种写法
  13. JDK10安装配置详解
  14. 小马哥STM32课程系列
  15. 电子签名在K2中的应用
  16. Numpy - Pandas - Matplot 功能与函数名 速查
  17. debian、ubuntu:使用apt包管理器可能存在的问题! 让新手望而却步!
  18. HDFS高可用性及其分布式系统思想基础
  19. log4net始终占用日志文件的问题
  20. Windows server 2012 R2开机进入cmd,关闭后黑屏问题

热门文章

  1. CodeForces - 233A Perfect Permutation
  2. 如何在SQLServer中处理每天四亿三千万记录的(数据库大数据处理)
  3. Javascript 中 的坑..
  4. abp使用redis缓存
  5. Myeclipse经常弹出Subversion Native Library Not Available
  6. Magic Odd Square (思维+构造)
  7. Axure8.0
  8. PIE SDK元素事件的监听
  9. linux + eclipse C语言 开发环境搭建
  10. spark第七篇:Spark SQL, DataFrame and Dataset Guide