How to bind 'touchstart' and 'click' events but not respond to both?

前端 未结 30 3557
抹茶落季
抹茶落季 2020-11-22 14:08

I\'m working on a mobile web site that has to work on a variety of devices. The one\'s giving me a headache at the moment are BlackBerry.

We need to support both key

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 14:11

    In my case this worked perfectly:

    jQuery(document).on('mouseup keydown touchend', function (event) {
    var eventType = event.type;
    if (eventType == 'touchend') {
        jQuery(this).off('mouseup');
    }
    });
    

    The main problem was when instead mouseup I tried with click, on touch devices triggered click and touchend at the same time, if i use the click off, some functionality didn't worked at all on mobile devices. The problem with click is that is a global event that fire the rest of the event including touchend.

提交回复
热议问题