Solve the Problem of webpage source or refresh in the drop-down list on the top of the mobile browser.

Source: Internet
Author: User

Solve the Problem of webpage source or refresh in the drop-down list on the top of the mobile browser.

Shows the problem:

Generally, there is an attribute "event. preventDefault () ", but if you use it directly, it will cause internal scrolling of the page to become unavailable, and the method I handle is similar to this.
Because the sliding area is backward, the distance from the top of the sliding block to the top of the browser is 0 (the remaining values are negative [$ ('# bodycthead '). offset (). top]). If it is 0, it indicates that it has already returned to the top. When it continues to pull down, there should be no response. You can disable the default sliding, when pulling up, the default slide should be canceled, so the "event. preventDefault () "is encapsulated into a function.
You need to determine whether to slide up or down. When you touch the screen, record a value of Y (scroll_start = e. changedTouches [0]. clientY;), a Y value (e. changedTouches [0]. clientY), two difference values (e. changedTouches [0]. clientY-scroll_start) if it is positive, it indicates that it is sliding downward, if it is negative, it is sliding upward.
Add event listening:

Var scroll_start = 0; // defines the starting point function handler () When sliding {// disables the default sliding function event. preventDefault ();} document. addEventListener ("touchstart", function (e) {scroll_start = e. changedTouches [0]. clientY; // set the point if ($ ('# bodycthead') when the start point is the touch '). offset (). top = 0) {// If the sliding block is at the top of the screen when the touch is reached, disable default sliding document. addEventListener ('touchmove ', handler, false) ;}}); document. addEventListener ("touchmove", function (e) {$ ("title" ).html (e. changedTouches [0]. clientY-scroll_start); if ($ ('# bodycthead '). offset (). top = 0) {// what you want to do is to interrupt the slide and disable the default slide. The method document for interruption is not found yet. addEventListener ('touchmove ', handler, false);} if (e. changedTouches [0]. clientY-scroll_start) <0) {// restores default sliding document if it is slide up. removeEventListener ('touchmove ', handler, false );}});

The sliding is not interrupted yet and the default sliding effect is prohibited. Thank you for your guidance!

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.