为什么在触摸式笔记本电脑上某些SPA不再支持触摸事件

也许我刚刚得出结论,并且每个人都知道了很长一段时间,但是事实证明,在Chrome 70中,他们做到了: ontouch * API在桌面上默认为禁用

因此,如果您在代码中依靠文档窗口中 “ ontouch *”键的存在,则您的代码将不再确定在触摸设备上起作用的内容。

我遇到了错字:

var isTouchDevice = (('ontouchstart' in window) || (navigator.MaxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)); 

当第一个条件不再成立时,第二个条件就搞砸了。 应该有navigator.maxTouchPoints

但是,例如,在jQuery UI Touch Punch 0.2.3中 ,使用以下代码:

  $.support.touch = 'ontouchend' in document; 

因此,也失去了支持。

Source: https://habr.com/ru/post/zh-CN429052/


All Articles