Use Iscroll to implement pull-up or pull-down refreshes

Source: Internet
Author: User

The need for pull-up or pull-up refreshes is a very common requirement on the mobile side, and in most cases, this effect is achieved using existing solutions on the web, such as someone using swiper this plugin and someone using iScroll the scroll plugin. The example in this article is a pull-down refresh effect that is implemented with Iscroll.

Iscroll Introduction

iScroolis one of the most mature custom scrolling solutions available, with good compatibility on mobile and PC. Iscroll officially offers 5 different versions:

    • The Iscroll.js General Edition contains most of the public features
    • Iscroll-lite.js reduced features such as scroll bars, mouse wheels, etc.
    • Iscroll-probe.js explore this release to meet your need to get the scroll bar position.
    • Iscroll-zoom.js Scrolling Zoom version
    • Iscroll-infinite.js Unlimited Plate Making

Depending on the requirements, select the appropriate version, in the current example, we select the iscroll-probe.js version.
Gitbook Address: Iscroll API Chinese version

Detailed use

The code idea is: the use of monitoring the scroll bar scroll events, determine the distance between pull-up or pull-up, make the trigger distance tag, when scrollEnd the event triggered, the data load execution. Let's look at the core part of the code:

HTML code structure
<divId="Myscroller"Class="Main"><divClass="Warpper"><divId="PullDown"Class="Scroller-pulldown"Style="Display:none;">Style="width:20px; height:20px;"Src="Rolling.svg"/><spanId="Pulldown-msg"Class="Pull-down-msg"> Drop-down Refresh</span></div><ulId=The Content"Class="Dropdown-list"></ul><divId="Pullup"Class="Scroller-pullup"Style="Display:none;">Style="width:20px; height:20px;"Src="Rolling.svg"/><spanId= "Pullup-msg" Span class= "token attr-name" >class=" Pull-up-msg "> pull up Refresh </span >  </div> </div></div>        
CSS Styles
. scroller{Position: Relative;Width:100%;Height:100%;}. scroller. warpper{Position: Absolute;Width:100%;}. Scroller-pulldown,. Scroller-pullup{Width:100%;Height:30px;Padding:10px0;Text-align: Center;}. dropdown-list{Padding:0;Margin:0;}. dropdown-list Li{Width:100%; background: #ddd; line-height: 45px; text-align: center; color: #FFF; border-bottom: 1px solid #FFF;}          
Javascript
var PullDown= document.Queryselector("#PullDown"), Pullup= document.Queryselector("#PullUp"), ispulled=False;Pull Markervar myscroll=NewIscroll(' #MyScroller ',{Probetype:3, MouseWheel:True, scrollbars:True, Preventdefault:False, Fadescrollbars:True}); myscroll.On(' Scroll ',function(){var height=This. Y, Bottomheight=This. maxscrolly-Height;Control drop-down displayIf(Height>=60){PullDown. style. display="Block"; Ispulled=True;Return;}ElseIf(Height<60&& height>=0){PullDown. style. display="None";Return;}Control Pull-Up displayIf(Bottomheight>=60){Pullup. style. display="Block"; Ispulled=True;Return;}ElseIf(Bottomheight<60&& Bottomheight>=0){Pullup. style. display="None";Return;}}) Myscroll.On(' Scrollend ',function(){Scroll EndIf (Ispulled{ Span class= "token comment" >//if trigger condition is reached, load ispulled = appendcontent (. Refresh}})               
For the full demo, please see:

Http://wewoor.github.io/js-lab/iscroll-pulldown-load/index.html

Original address:

http://imziv.com/blog/article/read.htm?id=73

Use Iscroll to implement pull-up or pull-down refreshes

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.