Mobile Note--jquery Touch event

Source: Internet
Author: User

Determine the mobile or PC-side
function IsPC ()  {             var useragentinfo = navigator.useragent;             var Agents = new Array ("Android", "IPhone", "SymbianOS", "Windows Phone", "IPad", "IPod");             var flag = true;             for (var v = 0, v < agents.length; v++) {                 if (Useragentinfo.indexof (Agents[v]) > 0) {flag = false; break;}             }             return flag;  }         

        $ (document). Bind (Touchevents.touchstart, function (event) {            event.preventdefault ();                    });
$ (document). Bind (Touchevents.touchmove, function (event) { event.preventdefault (); }); $ (document). Bind (Touchevents.touchend, function (event) { event.preventdefault (); });

Many blog post call Touch three events have targettouches,touches and Changedtouches object list, in fact, Touchend event should be only a changedtouches touch instance list, And here is a note that the event of the callback function is just a normal object object, in fact there is a Originalevent property in the event, this is the real touch event, there is an appeal three touch instance list, These three instances store the location of touch events and so on, similar to mouse events. Other places are basically consistent with mouse events. A brief introduction to these three touch lists, touches is a list of all the fingers on the screen, targettouches is the list of fingers on the current DOM, so when the finger moves off the trigger Touchend event, Event.originalevent does not have this targettouches list, and the Changedtouches list is a list of the current events, such as the Touchend event in which the finger is moved away. Next talk about the adaptation of PC and mobile, since the use of HTML5, of course, the cross-platform features, not only to iOS and Android adaptation, directly on the PC to open the Web page is also possible, but the PC only support mouse events how to do. Good, carefully observe the above code touch event, TOUCHEVENTS.TOUCHXXX, see the following code:

var touchevents = {        Touchstart: "Touchstart",        touchmove: "Touchmove",        touchend: "Touchend",        /**         * @desc: Determine if PC device, if PC, need to change touch event for mouse event, otherwise default touch event         */        inittouchevents:function () {            if (IsPC ())                { This.touchstart = "MouseDown";                This.touchmove = "MouseMove";                This.touchend = "MouseUp";}}    ;

If you are using mouse events on a PC, using touch events on your mobile device is as simple as that.

Source: http://blog.csdn.net/jiangcs520/article/details/17564065

  

  

Mobile Note--jquery Touch event

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.