//事例一
window.addEventListener("orientationchange", function() {
if(window.orientation === 90){
console.log('这是竖屏')
}
if(window.orientation === 0){
console.log('这是横屏')
}
}, false);
//事例二
// 判断屏幕是否旋转
function orientationChange() {
switch(window.orientation) {
case 0:
alert("肖像模式 0,screen-width: " + screen.width + "; screen-height:" + screen.height);
break;
case -90:
alert("左旋 -90,screen-width: " + screen.width + "; screen-height:" + screen.height);
break;
case 90:
alert("右旋 90,screen-width: " + screen.width + "; screen-height:" + screen.height);
break;
case 180:
alert("风景模式 180,screen-width: " + screen.width + "; screen-height:" + screen.height);
break;
};
};
// 添加事件监听
window.addEventListener('load', function(){
orientationChange();
window.onorientationchange = orientationChange;
});
js监听手机屏幕旋转
最新推荐文章于 2023-06-30 22:59:30 发布