我正在尝试使用事件侦听器记录我当前的方向状态-但由于某种原因,它不会触发。
if(window.orientation){
adjustHeader(window.orientation);
window.addEventListener("orientationchange", e => {
adjustHeader(window.orientation)
});
}else if(screen.orientation){
adjustHeader(screen.orientation);
window.addEventListener("orientationchange", e => {
adjustHeader(screen.orientation)
});
}
function adjustHeader(deviceOrientation){
if (Math.abs(deviceOrientation) === 90) {
// Landscape
alert("LANDSCAPE");
} else {
// Portrait
alert("PORTRAIT");
}
}