Find if device is touch screen then apply touch event instead of click event

前端 未结 4 1709
日久生厌
日久生厌 2020-12-22 01:52

I am creating a phonegap application, but as I came to know that it takes 300MS to trigger click event instead of touchevent.

I don\'t want to apply both event. Is t

4条回答
  •  误落风尘
    2020-12-22 02:17

    I mean really you should Modernizr but...

    var supportsTouch = 'ontouchstart' in window || navigator.msMaxTouchPoints;
    var eventType = supportsTouch ? 'ontouchstart' : 'click';
    

    Then declare your event listeners as such:

    $('#id').on(eventType, function(e) {
      alert('id was clicked');
    });
    

提交回复
热议问题