手机横屏和竖屏的代码(css3/javascript)

<!doctype html>
<html>
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <style type="text/css">
	@media screen and (orientation:portrait) {
		body{color:red}
	}

	@media screen and (orientation:landscape) {
		body{color:green;}
	}
  </style>
 </head>
 <body>
	横屏竖屏测试。
 </body>
</html>
<script type="text/javascript">
	window.addEventListener('orientationchange', function(event){
		if ( window.orientation == 180 || window.orientation==0 ) {
			alert("竖屏");
		}

		if( window.orientation == 90 || window.orientation == -90 ) {
			alert("横屏");
		}
	});
</script>