Achieve mobile pull-up loading effect

Source: Internet
Author: User

The implementation of pull-up loading is actually very simple:

1. Mobile-triggered Touchmove event (pull-up)

2. Determine if the last element has appeared at the bottom

3. If it appears, JS adds the element to the end of the page

Idea Map:

Next, start writing style styles:

html,body{    margin:0px;    width:100%;    height:100%;} li{    List-style:none;} #personkit_article_ul {    width:100%;    position:relative;    -webkit-padding-start:0;    -webkit-margin-before:0;    -webkit-margin-after:0;}. pin{    /*width:100%;*/    height:90px;    Background-color: #eee;    PADDING:6PX 8px;    position:relative;    border-bottom:1px solid #fff;}. personkit-article__img{    width:116px;    height:90px;}. Personkit-article__img img{    width:100%;    height:100%;}. personkit-article__info{    Position:absolute;    left:130px;    top:0px;    padding:0px 8px;}. personkit-article__title{    line-height:0px;} /* Multiple lines of text overflow for omission processing */.personkit-article__info p{    display:-webkit-box;    Overflow:hidden;    text-overflow:ellipsis;    -webkit-line-clamp:3;    -webkit-box-orient:vertical;}. bottom-line{    Text-align:center;    Background-color: #eee;}

HTML structure:

<section id= "Item" > <ul id= "Personkit_article_ul" > <li class= "pin" > <div class= " Personkit-article__img ">  </div> <div class=" Personkit-article__info "> &lt ; H3 class= "Personkit-article__title" > A book on health 

  

JS is implemented using the Zepto.js library:

<script src= ". /public/zepto.js "></script>

;(function(){    $(‘#personkit_article_ul‘).on(‘touchmove‘,function(){        //判断最后一个元素是否在底部之上        if( $(‘.pin‘).eq($(‘.pin‘).length-1).offset().top-$(window).scrollTop() < $(window).height() ){            $(‘.bottom-line‘).css(‘display‘,‘block‘).text(‘正在刷新...‘);            checkPull();        }    });    //添加元素方法    functioncheckPull(){        varpinNew;        pinNew=document.createDocumentFragment();        //每次添加5条内容        for(varj=5;j>0;j--){            varli=document.createElement(‘li‘);            li.className="pin";            li.innerHTML=‘<div class="personkit-article__img"></div><div class="personkit-article__info">

;            pinNew.appendChild(li);        }        $(‘#personkit_article_ul‘)[0].appendChild(pinNew);    }})(); The effect is to simulate the mobile side, the test can use Google browser-mail-review elements, click on the above already punctuate to see the effectThis article comes from reprint.

Achieve mobile pull-up loading effect

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.