Returns true if touch events are supported, false otherwise.

Check if ontouchstart exists in window or window.DocumentTouch is true and the current document is an instance of it.

代码片段

const supportsTouchEvents = () =>
  window &&
  ('ontouchstart' in window || window.DocumentTouch && document instanceof window.DocumentTouch);

使用样例

supportsTouchEvents(); // true