【问题标题】:Full Screen event on Touch not working on ChromeTouch 上的全屏事件在 Chrome 上不起作用
【发布时间】:2017-03-22 17:54:59
【问题描述】:

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

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

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

在控制台中出现错误:

在“元素”上执行“请求全屏”失败:API 只能是 由用户手势启动。 document.documentElement.webkitRequestFullScreen();

有人知道怎么解决吗?

【问题讨论】:

    标签: javascript android html google-chrome fullscreen


    【解决方案1】:

    您必须在 touchmove 上调用preventDefault(),并将new option 传递给addEventListener()。这对我有用:

    addEventListener('touchmove', onTouchMove, {passive: false});
    
    function onTouchMove(e) {
      e.preventDefault
    }
    

    【讨论】:

    • 这是有效的,因为您不能再在触摸事件上触发全屏当用户只是使用触摸滚动页面时。此代码阻止滚动,因此用户的滑动被视为真正的交互。
    • 从 Chrome 56 开始,'touchmove' 事件将不再触发用户手势,因此不能用于激活全屏模式。在使用上述代码后,您现在必须从 'touchend' 事件调用 requestFullscreen() 以防止默认的触摸滚动行为。 chromestatus.com/feature/6131337345892352
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 2013-01-22
    相关资源
    最近更新 更多