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

前端 未结 30 3367
抹茶落季
抹茶落季 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:30

    Why not use the jQuery Event API?

    http://learn.jquery.com/events/event-extensions/

    I've used this simple event with success. It's clean, namespaceable and flexible enough to improve upon.

    var isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
    var eventType = isMobile ? "touchstart" : "click";
    
    jQuery.event.special.touchclick = {
      bindType: eventType,
      delegateType: eventType
    };
    

提交回复
热议问题