screen.orientation.addEventListener('change', function() {
console.log('new orientation is ', screen.orientation.type);
});
window.addEventListener("orientationchange", function() {
if (window.orientation == 90 || window.orientation == -90) {
// landscape mode
} else {
// portrait mode
}
});
上面两张监听方向改变的方法,有什么区别呢?推荐哪个?
creen.orientation.addEventListener('change', function() {...})是根据 Screen Orientation API,
window.addEventListener("orientationchange", function() {...}):是根据window 对象的 "orientationchange" 事件和 window.orientation 属性,兼容性更好,但是角度少