iphone - 如何在网络应用程序中控制 iPhone 的屏幕方向

标签 iphone css webpage flot screen-orientation

我有一个非常基本的网页,它使用 flot 创建一个基于 canvas 的图表(类似于 SO 用于声誉图表的内容)。

如果是 PC 显示器,它应该只是正常输出,宽度(x 轴)是高度的 1.6 倍。

但对于 iPhone,我希望页面默认为横向,而不是让它以“纵向”方向溢出,鼓励(或强制)用户像 PC 用户一样转动手机来查看图表.

所以我的问题是:

1) 有没有办法(使用 CSS、JS 或简单的 HTML head 标签)让 Canvas 在检测到纵向时旋转 90 度?

2) 有没有一种方法可以旋转元素/对象,而不管谁在查看它?

3) 有没有办法避免 iPhone 在设备旋转时旋转内容的默认行为?显然,我希望用户在看到它出现在侧面时旋转设备,但我不希望图形翻转并且在他们转动手机时仍然在侧面,戏弄他们继续翻转手机并且永远不会得到图表保持静止。

谢谢!

最佳答案

像这样。

window.onorientationchange = function() {

  var orientation = window.orientation;
  switch(orientation) {
    case 0:

    document.body.setAttribute("class","portrait");

    break; 

    case 90:

    document.body.setAttribute("class","landscapeLeft");

    document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the left (Home button to the right).";
    break;

    case -90: 

    document.body.setAttribute("class","landscapeRight");

    document.getElementById("currentOrientation").innerHTML="Now in landscape orientation and turned to the right (Home button to the left).";
    break;
  }
}

关于iphone - 如何在网络应用程序中控制 iPhone 的屏幕方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1879386/

相关文章:

iphone - UIPickerView行图片选择高亮颜色

ios - 可以从哪个 View Controller 检查 segue 然后执行某些操作吗?

android - 页面未在 Android 浏览器中显示

html - 如何仅使用 ccs 创建三 Angular 形和正方形?

html - 在 github 页面中如何撤消主题选择器

linux - 使用 fifos 和链接从网页控制远程进程 (Linux)

iphone - 在 Objective-C 中获取 php 网站响应

iphone - 有关使用 wifi 远程访问 802.11 路由器上的客户端的应用程序的问题

css - 创建一个带有直 Angular 三 Angular 形/指针的按钮

html - 根据内容大小将 HTML 分成页面