在移动端,设备可以旋转,网页的宽度也会随着旋转而变化。为了适应这些变化,可以通过window.orientationchange事件来监听旋转,通过window.orientation或者screen.orientation.angle的值来判断旋转方向。
window.orientation:
0: 竖屏
-90:横屏,左在上
90:横屏,右在上
180:竖屏,倒置
screen.orientation.angle:
0: 竖屏,
90:横屏,右在上,
180:竖屏,倒置,
270:横屏,左在上e.g.
function show(){
document.write(window.orientation);
// document.write(screen.orientation.angle);
}
window.addEventListener('load', show);
window.addEventListener('orientationchange', show); 转载请注明带链来源:春语精椿

