2022年7月23日 星期六

detect portrait/landscape mode, don't use window.orientation

Math.abs(window.orientation) == 90 doesn't mean it's landscape mode. About 1% of android tablets consider that window.orientation == 0 in landscape mode. Therefore, window.orientation cannot be use, try this method instead:

window. addEventListener('resize', function(){
var dde = document.documentElement,
    rotation = dd.clientWidth > dd.clientHeight ? 'landscape' : 'portrait';

}, false);

Since onorientationchange always get the value before orientation, so we use onresize instead.