--- title: orientationchange slug: Web/API/Window/orientationchange_event tags: - API - Event - Window - onorientationchange - orientationchange - 参考 - 方向 translation_of: Web/API/Window/orientationchange_event ---

orientationchange事件在设备的纵横方向改变时触发。

Bubbles No
Cancelable No
Interface {{domxref("Event")}}
Event handler {{domxref("Window/onorientationchange", "onorientationchange")}}

示例

你可以在{{domxref("EventTarget/addEventListener", "addEventListener")}} 方法中使用 orientationchange 事件:

window.addEventListener("orientationchange", function() {
  console.log("the orientation of the device is now " + screen.orientation.angle);
});

或者使用 {{domxref("Window/onorientationchange", "onorientationchange")}} 事件处理程序属性:

window.onorientationchange = function() {
  console.log("the orientation of the device is now " + screen.orientation.angle);
};

规范

规范 状态
{{SpecName('Compat', '#event-orientationchange', 'orientationchange')}} {{Spec2('Compat')}}

浏览器兼容性

{{Compat("api.Window.orientationchange_event")}}