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

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

    For simple features, just recognize touch or click I use the following code:

    var element = $("#element");
    
    element.click(function(e)
    {
      if(e.target.ontouchstart !== undefined)
      {
        console.log( "touch" );
        return;
      }
      console.log( "no touch" );
    });
    

    This will return "touch" if the touchstart event is defined and "no touch" if not. Like I said this is a simple approach for click/tap events just that.

提交回复
热议问题