Javascript触摸事件:区分手指与Apple Pencil [英] Javascript touch event: distinguishing finger vs. Apple Pencil

查看:667
本文介绍了Javascript触摸事件:区分手指与Apple Pencil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mobile Safari中,有没有办法区分手指或Apple Pencil是否产生触摸事件?

In Mobile Safari, is there any way to distinguish whether a touch event is generated by finger or Apple Pencil?

推荐答案

触摸事件的 TouchList 对象包含有关触摸各个点的详细信息。在众多属性中, touchType 可能是最有趣的,因为它包含手写笔(Apple Pencil)或直接 (手指)。

The TouchList object of a touch event contains detailed information about the touch’s individual points. Among the many properties touchType is probably the most interesting for you as it contains either stylus (Apple Pencil) or direct (finger).

var body = document.getElementByTagName('body');
body.addEventListener('touchstart', function(evt){
    // should be either "stylus" or "direct"
    console.log(evt.touches[0].touchType);
});

您还应该查看每个Touch的其他属性,如强制 azimuthAngle 可以为您提供有关触摸点当前设备的详细信息。

You should also have a look at the other properties of each individual Touch like force or azimuthAngle that can give you detailed information about the touch point’s current device(s).


请注意,Touch界面只是 W3C工作
草稿
而不是官方标准 - 但适用于iOS 10 +
Safari + Apple Pencil。

Please note that the Touch interface is only part of a W3C working draft and not official standard yet – however works in iOS 10 + Safari + Apple Pencil.

这篇关于Javascript触摸事件:区分手指与Apple Pencil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆