h5监听方向变化?
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 属性,兼容性更好,但是角度少
以上是 h5监听方向变化? 的全部内容, 来源链接: utcz.com/p/934570.html