移动屏幕方向锁无法正常工作



我正在尝试使用此处指定的屏幕定位API锁定屏幕方向:替代方向此处:https://w3c.github.io/screen-orientation/#examples

API仍在工作草案中,但它表明Chrome和Firefox支持它,但我无法正常工作。

我尝试了以下内容:
1)

screen.orientation.lock('portrait').catch(function() { /*Do Nothing*/ });

2)

screen.lockOrientationUniversal = screen.lockOrientation || screen.mozLockOrientation || screen.msLockOrientation;
if (screen.lockOrientationUniversal(["portrait"])) {
  // orientation was locked
} else {
  // orientation lock failed
}

,但它不适用于Chrome Mobile。

对于chrome和本机浏览器,例如三星互联网,您首先需要访问全屏,然后才能设置方向锁,可以通过document.body.body.body.requestfullscreen来完成。返回诺言。成功时,您可以锁定方向。

最新更新