Why does the browser touchend event of Android fail to be triggered? -

Source: Internet
Author: User
Click should trigger the touchstart and touchend events, but the Android phone does not trigger the touchend. How can I solve this problem? Click should trigger the touchstart and touchend events, but the Android phone does not trigger the touchend. How can I solve this problem? Reply: The touch event does not trigger the touchend event because of an inexplicable compatibility problem in the mobile browser!

Http://code.google.com/p/android/issues/detail? Id = 19827
Working with touch events
On Android ICS if no preventDefault is called on touchstart or the first touchmove, further touchmove events and the touchend will not be fired.
As a workaround we need to decide in the first touchmove if this is a scroll (so we don't call preventDefault) and then manually trigger touchend.

If you do not have much concern (about scroll), use event in the handle of touchstart. preventDefault () can trigger the touchend event normally. Thanks to the inexplicable problem, this problem has been encountered during development in recent days. The project needs to simulate an app to pull down the loading effect. My solution is to add e. preventDefault (): removes the default sliding inertia of the browser, so that it does not interfere with the trigger of the touchend event, and then handwriting the sliding effect. In addition, you need to determine whether sliding occurs, avoid interfering with the default click effect:
Var x, y, z;

Var slideCouter = 1; var hasMoved = false; var checking = false; var hasMore = true; $ (document ). on ('touchstart', function (e) {z = $ (document ). scrollTop (); x = event.tar getTouches [0]. pageY ;}). on ('touchmove ', function (e) {e. preventDefault (); hasMoved = true; y = event.tar getTouches [0]. pageY; z + = x-y; $ (document ). scrollTop (z );}). on ('touchend', function (e) {if (x-y> 200 &&! Checking & hasMoved & hasMore) {checking = true; slideCouter ++; $ ('. login'). removeClass ('None'); $. ajax ({url :"
  CreateUrl ('/teacher/categoryMore');?> ", Type:" get ", data: {" keyword ":'
  ', "Page": slideCouter}, cache: false, success: function (data) {completecall (data) ;}}) ;}hasmoved = false ;}); ================== currently, other methods have more or less drawbacks. The disadvantage of this method is that the sliding inertia is canceled, the effect of self-writing is not so smooth, but it is a good solution to this compatibility problem.
You can monitor touchcancel events at the same time. @ Jack king use touchcancel. In android4.4, a copy of text or the like will appear.
I also want to know about the situation of copying text. I also encountered this problem. I need to worry about scroll and prevent the default event. If I use touchcancel, I will see copying text in android4.4, how can this problem be solved? @ Bo I have to worry about scroll. How can I solve this problem?

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.