【问题标题】:jquery detect phone orientationjquery检测手机方向
【发布时间】:2015-06-11 15:51:57
【问题描述】:

我编写了一些代码,提醒用户在手机上更改为横向基本上转到纵向。这很好用,但如果用户从横向开始,它显然不会显示,因为没有方向变化。有没有办法获得 get go 的方向?

$(window).on("orientationchange",function(){
        if( (window.orientation == 90 && $( window ).width() < 780) || (window.orientation == -90 && $( window ).width() < 780) ) // Landscape
        {
          $('body').append('<div class="phoneLandscape"><h4>Sorry, this site is best viewed in Portrait Mode</h4></div>');
        }
        else // Portrait
        {
          $('.phoneLandscape').remove();
        }
      });

【问题讨论】:

标签: jquery


【解决方案1】:

jQuery mobile 有 $(window).on("orientationchange") 方法,但如果你想在任何给定时间检测方向,试试这个

if(window.innerHeight > window.innerWidth){
    //portrait
}
if(window.innerWidth > window.innerHeight){
    //landscape
}

【讨论】:

  • 但这不会影响非移动设备吗?如果您只想将其应用于移动设备怎么办?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-27
  • 1970-01-01
  • 2017-10-18
  • 2011-10-23
相关资源
最近更新 更多