Interface Orientation Document

InterfaceOrientation

获取应用的横竖屏信息

方法:

事件:

window.orientation

获取当前设备横竖屏状态

var screen_orientation = window.orientation;
				

参数:

返回值:

number : 0 正常方向 -90 屏幕顺时钟旋转90度 90 屏幕逆时针旋转90度 180 屏幕旋转180度

平台支持:

orientationchange

当屏幕旋转时的通知事件

document.addEventListener("orientationchange", orientationchangeCB);
				

说明:

orientationchangeCB 类型

平台支持:

示例:

<!DOCTYPE html>
<html>
	<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
	<title>Orientation Example</title>
	<script type="text/javascript" >

		function updateOrientation() {
		  var displayStr = "Orientation : ";
		  switch(window.orientation)
		  {
			case 0:
			  displayStr += "Portrait";
			  break;
			case -90:
			  displayStr += "Landscape (right, screen turned clockwise)";
			  break;
			case 90:
			  displayStr += "Landscape (left, screen turned counterclockwise)";
			  break;
			case 180:
			  displayStr += "Portrait (upside-down portrait)";
			  break;
		  }
		  document.getElementById("output").innerHTML = displayStr;
		}

		//Get initialize orientation. 
		document.addEventListener("orientationchange", updateOrientation());

	</script>
	</head>
	<body style="background:#0f0" >
	<div id="output"></div>
	</body>
</html>