(一)利用iscroll写出来的上拉加载下拉刷新

本节知识点

  • 知识概况

代码

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0">
    <title>Title</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/iscroll.js"></script>
</head>
<style>
    *{margin:0px;padding:0px;}
    ul{list-style-type:none;}
    html,body{width:100%;height:100%;}
    header{width:100%;height:10%;text-align:center;line-height:50px;background:black;color:white;font-size:12px;}
    footer{width:100%;height:10%;text-align:center;line-height:50px;background:black;color:white;font-size:12px;}
     .box{width:100%;height:80%;overflow:hidden;}
    #wrap{width:100%;height:auto;}
    .shuaxin{width:100%;height:20px;text-align:center;background:#ccc;color:black;display:none;}
    #wrap li{width:100%;line-height:150px;color:yellow;background:blue;text-align:center;border-bottom:1px dashed yellow;}
    .jiazai{width:100%;height:20px;text-align:center;background:#ccc;color:black;display:none;}
</style>
<body>
<header>这个就是测试上拉加载和下拉刷新</header>
<div class="shuaxin">你在下拉刷新</div>
 <div class="box">
      <ul id="wrap">
          <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 class="jiazai">你是在上拉加载</div>
<footer>这个就是底部</footer>
</body>
<script>
    $(function(){

        var myscroll = new IScroll('.box');
        $(document).on("touchend",function(){
            console.log(myscroll.y);
            if(myscroll.y==0)
            {
                $(".shuaxin").hide();
            }
            if(myscroll.y==myscroll.maxScrollY)
            {
                $(".jiazai").hide();
            }
              myscroll.refresh();
        });
        $(document).on("touchmove",function(){
            console.log(myscroll.y);
            if(myscroll.y>20)
            {
              $(".shuaxin").show();
            }
            if(myscroll.y<myscroll.maxScrollY-20)
            {
                $(".jiazai").show();
            }
        })


    })

</script>
</html>

要想滚动到某一个位置

  • scrollTo(x,y,time,relative)

  • scrollToElement(ele,time)

  • snapToPage(pagex,pageY,time)

2018-02-24_075730.jpg
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 什么是事件: 我们可以简单的把事件理解为浏览器的感知系统。比如说:他可以感觉到用户是否点击(click)了页面、鼠...
    张松1366阅读 11,792评论 1 6
  • 最近的一次开发中,使用到了overflow:scroll 属性来滑动div。如果你对某个div或模块使用了over...
    独享奢华阅读 64,650评论 3 24
  • offset家族三大家族和一个事件对象三大家族(offset/scroll/client)事件对象/event ...
    Yuann阅读 4,560评论 0 5
  • // 正则判断手机号码地址格式
    by小杰阅读 1,014评论 0 0
  • 对别人好是一种天赋,而你遇见怎样的人,别人会怎么对你,却是你的运气。
    蛋糕上的栗子阅读 1,378评论 0 0