Iscroll. js pull-up and pull-down solutions that cannot rebound when refreshing, iscroll. js pull-down

Source: Internet
Author: User

Iscroll. js pull-up and pull-down solutions that cannot rebound when refreshing, iscroll. js pull-down

I used iscroll. all of my friends who pull up and pull the refresh effect in js should have encountered this problem: In the iOS browser, when pulling up or pull down the refresh, the page cannot be displayed when the screen is drawn by the finger. Many people simply don't solve this problem because they can't solve it. Some people simply don't need HTML, and use native instead of HTML pages.

I believe many of my friends have their own solutions, but they did not write them out, so they cannot find the solutions on the Internet. Many people in many QQ groups are asking how to solve this problem. So I wrote this article to record my solution and hope it would be helpful to some friends.

The main code for pulling and refreshing is as follows:

 myScroll = new iScroll('wrapper', {  vScrollbar: false,  useTransition: true,  topOffset: pullDownOffset,  onRefresh: function () {   if (pullDownEl.className.match('loading')) {    pullDownEl.className = '';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';   } else if (pullUpEl.className.match('loading')) {    pullUpEl.className = '';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';   }  },  onScrollMove: function () {   if (this.y > 5 && !pullDownEl.className.match('flip')) {    pullDownEl.className = 'flip';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Release to refresh...';    this.minScrollY = 0;   } else if (this.y < 5 && pullDownEl.className.match('flip')) {    pullDownEl.className = '';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Pull down to refresh...';    this.minScrollY = -pullDownOffset;   } else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {    pullUpEl.className = 'flip';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Release to refresh...';    this.maxScrollY = this.maxScrollY;   } else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {    pullUpEl.className = '';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Pull up to load more...';    this.maxScrollY = pullUpOffset;   }  },  onScrollEnd: function () {   if (pullDownEl.className.match('flip')) {    pullDownEl.className = 'loading';    pullDownEl.querySelector('.pullDownLabel').innerHTML = 'Loading...';    pullDownAction();   } else if (pullUpEl.className.match('flip')) {    pullUpEl.className = 'loading';    pullUpEl.querySelector('.pullUpLabel').innerHTML = 'Loading...';    pullUpAction();   }  } });

The cause of page bounce failure is that the touchend event cannot be triggered after the screen is drawn by the finger, and the rebound animation cannot be executed. The solution is to manually trigger the animation when the finger approaches the edge of the screen.

Insert the judgment code in the onScrollMove method:

  onScrollMove: function () {   if((this.y < this.maxScrollY) && (this.pointY < 1)){    this.scrollTo(0, this.maxScrollY, 400);    return;   } else if (this.y > 0 && (this.pointY > window.innerHeight - 1)) {    this.scrollTo(0, 0, 400);    return;   }   ......  }

The following explains the meaning of this Code.

This. y is the vertical distance of the page that has been rolled, this. maxScrollY is the maximum vertical rolling distance, and this. pointY is the current vertical coordinate of the finger.

When this. y <this. maxScrollY is the process of pulling up, when (this. y <this. maxScrollY) & (this. pointY <1) is in the upper position and the finger has reached the edge of the screen. this is triggered manually. scrollTo (0, this. maxScrollY, 400.

The drop-down process can also be analyzed in the same way.

Articles you may be interested in:
  • JQuery plug-in iScroll implements drop-down refresh and scrolling pages.
  • Two solutions are triggered when an event is clicked in iScroll.

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.