微网站-上拉、下拉刷新(重新请求数据)_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 08:58:42
Original
1452 people have browsed it

PC端的分页和移动端的分页是不一样的,如果移动端像PC端那样点击上一页、下一页,或者点击具体的页码,那样用户体验是非常差的。上拉刷新、下拉刷新这样的操作,是我们希望实现的效果,那么这种效果该如何实现呢?

下面dropload.min.js闪亮登场,我们直奔主题
  • 项目准备
    • zepto.min.js
    • dropload.min.js
    • 上拉下拉刷新的css样式(下面会详情说)
  • 项目效果图1.这是上拉刷新

pic1.png

2.这是上拉刷新

pic2.png

  • 图上的加载中的效果是如何加上去的?
    页面源码<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <title>demo</title>  <link rel="stylesheet" href="index.css"></head><body>  <div class="wrap">      <div class="inner">        <div class="lists">            <a class="item" href="#">                <img src="goods.jpg" alt="">                <h3>1文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="goods.jpg" alt="">                <h3>2文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="goods.jpg" alt="">                <h3>3文字描述文字描述文字描述文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="goods.jpg" alt="">                <h3>4文字描述文字描述文字描述文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="goods.jpg" alt="">                <h3>5文字描述文字描述文字描述文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>        </div>    </div></div><script src="zepto.min.js"></script><script src="dropload.min.js"></script><script src="index.js"></script></body></html>
    Copy after login
    index.js// droploadvar dropload = $('.inner').dropload({  domUp : {      domClass   : 'dropload-up',      domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',      domUpdate  : '<div class="dropload-update">↑释放更新</div>',      domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'  },  domDown : {      domClass   : 'dropload-down',      domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',      domUpdate  : '<div class="dropload-update">↓释放加载</div>',      domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'  },  loadUpFn : function(me){      alert("上拉刷新操作");      me.resetload();  },  loadDownFn : function(me){       alert("下拉刷新操作");       me.resetload();  }});
    Copy after login
    我们可以在loadUpFn,loadDownFn中指定新的ajax请求,将ajax返回的结果按照页面所需的形式追加到容器中。说到这里,还没有结束,页面中的加载中的动画是怎么实现的呢?细心的估计已经看到了上面的js中,有这么一段代码:
    domUp : {      domClass   : 'dropload-up',      domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',      domUpdate  : '<div class="dropload-update">↑释放更新</div>',      domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'  },  domDown : {      domClass   : 'dropload-down',      domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',      domUpdate  : '<div class="dropload-update">↓释放加载</div>',      domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'  },
    Copy after login
    这里,我通过css3动画来实现了类似gif动态图的效果,附上源码:
    .dropload-up,.dropload-down {  position: relative;  height: 0;  overflow: hidden;  -webkit-transform: translate3d(0, 0, 0);  transform: translate3d(0, 0, 0)}.dropload-refresh,.dropload-update,.dropload-load {  position: absolute;  left: 50%;  bottom: 0;  width: 100%;  height: 50px;  line-height: 50px;  text-align: center;  -webkit-transform: translate(-50%, 0);  transform: translate(-50%, 0)}.dropload-down .dropload-refresh,.dropload-down .dropload-update,.dropload-down .dropload-load {  top: 0;  bottom: auto}.dropload-load .loading {  display: inline-block;  height: 15px;  width: 15px;  border-radius: 100%;  margin: 6px;  border: 2px solid #666;  border-bottom-color: transparent;  vertical-align: middle;  -webkit-animation: rotate .75s linear infinite;  animation: rotate .75s linear infinite}@-webkit-keyframes rotate {  0% {      -webkit-transform: rotate(0deg)  }  50% {      -webkit-transform: rotate(180deg)  }  100% {      -webkit-transform: rotate(360deg)  }}@keyframes rotate {  0% {      transform: rotate(0deg)  }  50% {      transform: rotate(180deg)  }  100% {      transform: rotate(360deg)  }}
    Copy after login
    好了,实现这个效果就这么多内容。这里是很灵活的,你也可以自己组织加载请求时得动画效果。快动手试试,应用在你的项目中吧~(PS:列表的css源码不在此,如果你想要整个工程的源码,你可以发我简信,或者在我的个人主页加我微信~)
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template