Mobile web page pull-down refresh

Source: Internet
Author: User

Mobile web page pull-down refresh
1. Use the touch event touchmove. 1. Define the public variable var timer = null; var startY, moveY, initTop, oldTop, newTop; 2. Add event $ ('# container ul '). on ('touchstart', function (e) {startY = e. originalEvent. touches [0]. pageY; initTop = 0 ;}); $ ('# container ul '). on ('touchmove ', function (e) {moveY = e. originalEvent. touches [0]. pageY; scrollEnd () ;}); 3. function scrollEnd () {if (timer) clearTimeout (timer); newTop =$ (window ). scrollTop (); if (newTop === oldTop) {ClearTimeout (timer); if (initTop! = NewTop) {var wHeight = $ (window ). height (); var dHeight = $ (document ). height (); if (newTop> 0) & (newTop + wHeight> = dHeight) & (startY-moveY> 0 )) {// run the Business Code }}else {oldTop = newTop; timer = setTimeout (scrollEnd, 100) ;}ii. Use the scroll event $ (window ). scroll (function () {var scrollTop = $ (this ). scrollTop (); // var distance entheight = $ (document) from the height of the scroll bar to the Y axis ). height (); // The height of the entire window var height = $ (this ). height (); // The height of the visible area if (scrollTop + height) = incluentheight) {// execute Business Code }});

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.