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

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="/static/imghwm/default1.png"  data-src="goods.jpg"  class="lazy" alt="">                <h3 id="文字描述文字描述">1文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="/static/imghwm/default1.png"  data-src="goods.jpg"  class="lazy" alt="">                <h3 id="文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述">2文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="/static/imghwm/default1.png"  data-src="goods.jpg"  class="lazy" alt="">                <h3 id="文字描述文字描述文字描述文字描述文字描述">3文字描述文字描述文字描述文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="/static/imghwm/default1.png"  data-src="goods.jpg"  class="lazy" alt="">                <h3 id="文字描述文字描述文字描述文字描述文字描述">4文字描述文字描述文字描述文字描述文字描述</h3>                <span class="date">2015-11-27</span>            </a>            <a class="item" href="#">                <img src="/static/imghwm/default1.png"  data-src="goods.jpg"  class="lazy" alt="">                <h3 id="文字描述文字描述文字描述文字描述文字描述">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>
    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();  }});
    我们可以在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>'  },
    这里,我通过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)  }}
    好了,实现这个效果就这么多内容。这里是很灵活的,你也可以自己组织加载请求时得动画效果。快动手试试,应用在你的项目中吧~(PS:列表的css源码不在此,如果你想要整个工程的源码,你可以发我简信,或者在我的个人主页加我微信~)
Statement
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
What is the difference between an HTML tag and an HTML attribute?What is the difference between an HTML tag and an HTML attribute?May 14, 2025 am 12:01 AM

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The Future of HTML: Evolution and TrendsThe Future of HTML: Evolution and TrendsMay 13, 2025 am 12:01 AM

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

Why are HTML attributes important for web development?Why are HTML attributes important for web development?May 12, 2025 am 12:01 AM

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

What is the purpose of the alt attribute? Why is it important?What is the purpose of the alt attribute? Why is it important?May 11, 2025 am 12:01 AM

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

HTML, CSS, and JavaScript: Examples and Practical ApplicationsHTML, CSS, and JavaScript: Examples and Practical ApplicationsMay 09, 2025 am 12:01 AM

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

How do you set the lang attribute on the  tag? Why is this important?How do you set the lang attribute on the tag? Why is this important?May 08, 2025 am 12:03 AM

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

What is the purpose of HTML attributes?What is the purpose of HTML attributes?May 07, 2025 am 12:01 AM

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

How do you create a list in HTML?How do you create a list in HTML?May 06, 2025 am 12:01 AM

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools