通过window.orientation来判断设备横竖屏
function checkOrient() {
        
    if (window.orientation == 0 || window.orientation == 180){
        var screenOrientation = 'portrait';
    }
    else if (window.orientation == 90 || window.orientation == -90){
        var screenOrientation = 'landscape';
    }
    return screenOrientation;
}
// 添加事件监听
addEventListener('load', function(){
    checkOrient();
    window.onorientationchange = checkOrient;
});

注:landscape是横向,portrait是纵向


转自:http://www.best-html5.net/?p=661

相关文章:

  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2021-07-11
  • 2021-11-23
猜你喜欢
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案