Touch 上的全屏事件在 Chrome 上不起作用

And*_*nko 3 html javascript android google-chrome fullscreen

在我的移动应用程序中,我想在用户向上滑动时切换全屏。
因此,当touchend事件被触发时,我调用 document.documentElement.webkitRequestFullScreen();
问题是它在移动 Chrome 56+ 中不适用于我。

这是一个例子。 https://jsfiddle.net/ibmw/tnncaxj0/6/

有趣的是:只有当您在 touchstart 和 touchend 之间进行 touchmove 时才会出现此问题。

在控制台中我收到一个错误:

无法在“Element”上执行“requestFullscreen”:API 只能通过用户手势启动。document.documentElement.webkitRequestFullScreen();

有谁知道如何奋斗吗?

And*_*nko 5

您必须调用preventDefault()touchmove,并将新选项传递给addEventListener(). 这对我有用:

addEventListener('touchmove', onTouchMove, {passive: false});

function onTouchMove(e) {
  e.preventDefault
}
Run Code Online (Sandbox Code Playgroud)