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!