Chrome(桌面)触摸仿真不工作

Chrome (Desktop) touch emulation not working

我写了一点 javascript 并尝试在最新的稳定版 Chrome 上为 Windows 10 调试它(截至编写 v48)..

该脚本与鼠标输入完美配合,但一旦我模拟 mobile/touchdevice 并启用触摸模拟 - 它不起作用,相应的 console.logs 告诉我没有检测到触摸.. .

function hasTouch() {
        return 'ontouchstart' in document.documentElement;
}
var event_start = hasTouch() ? 'touchstart' : 'mousedown',
    event_move = hasTouch() ? 'touchmove' : 'mousemove',
    event_end = hasTouch() ? 'touchend' : 'mouseup';
console.log(event_start + "|" + event_move + "|" + event_end);

带有触摸仿真功能的 Firefox 完美运行!物理触摸设备也能完美工作..

https://jsfiddle.net/j8kLz6wm/1/

所以Chrome有什么问题?

您应该像这样重写 hasTouch 函数:

function hasTouch() {
  return 'ontouchstart' in window;
}