Using jquery mobile tap instead of click

后端 未结 1 1845
隐瞒了意图╮
隐瞒了意图╮ 2021-02-06 09:06

I\'m making a web application that needs to run on both mobile devices as well as non-mobile devices. In my application I have several icons the user can click in order to send

相关标签:
1条回答
  • 2021-02-06 09:47

    jQuery Mobile special events i.e. tap, taphold, vclick...etc, are originally touch and mouse events converted into special events.

    For example, tap and vclick are either touchstart/touchend or mousedown/mouseup.

    On loading jQuery Mobile, it checks if browser supports touch and accordingly events are converted into mouse events or touch events.

    You can alternate between events depending on browser's touch support. For non-touch browsers, use click and the ones that support touch, use tap.

    On start-up, check $.support.touch, it will return true (tap) or false (click).

    var custom_event = $.support.touch ? "tap" : "click";
    
    $(document).on(custom_event, "element", function () {
      /* code */
    });
    

    Test the below demo on your desktop and mobile.

    Demo

    0 讨论(0)
提交回复
热议问题