gpt4 book ai didi

javascript - 已弃用 : Window: orientationchange event

转载 作者:行者123 更新时间:2023-12-04 17:18:11 26 4
gpt4 key购买 nike

orientationchange事件已被弃用。

window.addEventListener("orientationchange", function(event) {
console.log(event.target.screen.orientation.angle);
});
窗口:orientationchange 事件

DeprecatedThis feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.


我现在可以使用什么?有没有其他方法可以做到这一点?

最佳答案

我们可以使用实验功能 ScreenOrientation

screen.orientation.addEventListener('change', function(e) { ... })
screen.orientation.onchange = function(e) { ... }
您可以从 screen orientation table 查看可用值对于方向类型:
  • 肖像主要
  • 肖像中学
  • 景观-主要
  • 景观中学

  • 这是一个例子:
    screen.orientation.addEventListener('change', function(e) {
    if (e.currentTarget.type === 'landscape-primary') {
    // landscape mode => angle 0
    } else if (e.currentTarget.type === 'portrait-primary') {
    // portrait mode => angle 0
    }
    })
    查看 browser compatibility table .

    关于javascript - 已弃用 : Window: orientationchange event,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67961837/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com