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 "> < ; 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