Solve the problem of pulling out the current webpage source or refresh under the top of the mobile browser

Source: Internet
Author: User

The problem is as follows:

The general handling of such problems will have a property: "Event.preventdefault ()", but if used directly will cause the page's internal scrolling also to fail to be able to scroll, I am dealing with a similar way.


Because the sliding area is moving, the top of the slider is up to 0 from the top of the browser (the rest is negative [$ (' #bodycthead '). Offset (). Top]), when 0 indicates that it has returned to the top,

Continue to pull down when there should be no reaction, you can disable the default sliding, and pull up when the default sliding should be canceled, so the "Event.preventdefault ()" should be encapsulated into a function.

All you need to do is to determine if you want to swipe up or down and record a Y value when touching the screen (Scroll_start = E.changedtouches[0].clienty;), and a Y value will be generated when moving.

(E.changedtouches[0].clienty), two worth difference (E.changedtouches[0].clienty-scroll_start) If a positive value indicates a downward slide, and if it is negative, swipe up.


To add an event listener:

varscroll_start=0;//defining the starting point when slidingfunction handler () {//Disable default sliding function    Event. Preventdefault ();} Document.addeventlistener ("Touchstart", Function (e) {Scroll_start= e.changedtouches[0].clienty;//set the point at which the start point is touch    if($('#bodycthead'). Offset (). top==0){//If you touch the slider at the top, disable the default swipeDocument.addeventlistener ('Touchmove', Handler,false); }});d Ocument.addeventlistener ("Touchmove", Function (e) {$ ("title"). HTML (e.changedtouches[0].clienty-Scroll_start); if($('#bodycthead'). Offset (). top==0){//What you want to do is break the slide and disable the default swipe, temporarily not finding the way to breakDocument.addeventlistener ('Touchmove', Handler,false); }    if((e.changedtouches[0].clienty-scroll_start) <0){//If you swipe up, restore the default swipeDocument.removeeventlistener ('Touchmove', Handler,false);      }}); 

Solve the problem of pulling out the current webpage source or refresh under the top of the mobile browser

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.