javascript - ipad portrait 的特定 JS 也在 landscape 中触发

标签 javascript ios ipad css

JS

if (screen.width <= 768 && screen.width != 1024) { 
     jQuery('.menu-link').bind("click touchstart", function() {
          if (jQuery('#wrap3').css("left") === "0px"){
              jQuery('#wrap3').animate({"left":"17%"}, 50);
          }
          else {
              jQuery('#wrap3').animate({"left":"0"}, 50)
          }
     });
  }

我原来是这样试的

if (screen.width <= 768)

它在纵向上工作正常,但在不应该的情况下在横向上工作。

我该如何解决这个问题?

它也不能在桌面上运行,这正是我想要的。

旁注 - 这是为不同的移动宽度创建不同的 JS 的常见做法吗?我使用 JS 而不是 CSS3 的原因是因为我尝试做的动画在 ipad 上不起作用。

最佳答案

你能做些检查高度和宽度之类的事情吗?

if (window.innerheight>window.innerWidth)
{
    alert("Landscape Please!");
}

来源:Detect viewport orientation, if orientation is Portrait display alert message advising user of instructions

关于javascript - ipad portrait 的特定 JS 也在 landscape 中触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22674361/

相关文章:

ios - 如何在ipad上以单应用模式打开设置

cocoa-touch - 获取 UIGestureRecognizer 消息的已释放对象

iphone - 如何在 IndexPath 处使用 reloadRows 更新行

javascript - Q Promise 等效于 BlueBird Promise.Bind()

iOS 谷歌标签管理器在启动时崩溃 'NSParseErrorException',原因 : 'Last tag: 116 should be 124'

javascript - 如何在 Angular ng-repeat中使用累积和

ios - 在 Master-Detail 应用程序中为 Master/Detail View Controller 重用 UIViewController(带有 UITableView)?

ios - 检查 firebase 数据库中是否存在用户名。

javascript - 如果return else else return或return后接隐式else return,是否认为写得更好?

javascript - Angular ui-router 中 $state.transitionTo() 和 $state.go() 的区别