【发布时间】:2021-06-09 09:24:53
【问题描述】:
在我的 Ionic 应用程序上旋转设备时,我尝试全屏渲染视频。我正在使用 this plugin 来捕捉设备旋转和 FullScreen API。
window.screen.orientation.addEventListener("change", function () {
if (window.screen.orientation.type.startsWith("landscape") && !document.fullscreenElement) {
try { container.requestFullscreen();
} catch (err) {...); }
} else if ( window.screen.orientation.type.startsWith("portrait") && document.fullscreenElement )
{ try { document.exitFullscreen(); } catch (err) { ... } } }); });
如果我在旋转设备之前触摸视频,这可以正常工作,但如果我不触摸它,我会收到此错误
消息:无法在“元素”上执行“请求全屏”:API 只能 由用户手势启动。
根据MDN 这应该可以工作。 我也尝试过“window.addEventListener("orientationchange",..." 但它看起来并没有改变。我错过了什么吗?
【问题讨论】:
标签: ionic-framework fullscreen screen-orientation