行動版網頁常需偵測橫豎屏切換。orientationchange 在部分瀏覽器相容性不佳,可搭配 resize 或 CSS media query。
window.addEventListener("orientationchange", function(event){
// 依 orientation 判斷
}, false);
orientationchange 的相容性如下:

screen.orientation 的相容性如下:

var orientation = window.innerWidth > window.innerHeight ? "landscape" : "portrait";
可動態注入 CSS,透過 font-family 是否命中 portrait 或 landscape 來判斷狀態。

portrait 效果:

landscape 效果:

最終可封裝為 orientationchange-fix,在支援時使用原生事件,不支援時使用 resize 或樣式偵測。