首页 > 移动平台 > 详细

移动端横屏(beta)

时间:2016-05-16 11:04:05      阅读:268      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>Document</title>

</head>

<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>

<script>

var orientation=0;

function screenOrientationEvent(){

if(orientation == 0)

{

document.getElementById("change").value="竖";

$("body").css({

‘transform‘:‘rotate(90deg)‘,

‘-webkit-transform‘:‘rotate(90deg)‘,

‘-moz-transform‘:‘rotate(90deg)‘

});

}

else

{

document.getElementById("change").value="横";

$("body").css({

‘transform‘:‘rotate(0deg)‘,

‘-webkit-transform‘:‘rotate(0deg)‘,

‘-moz-transform‘:‘rotate(0deg)‘

});

}

}

var innerWidthTmp = window.innerWidth;

//横竖屏事件监听方法

function screenOrientationListener(){

try{

var iw = window.innerWidth;

//屏幕方向改变处理

if(iw != innerWidthTmp){

if(iw>window.innerHeight)

{

orientation = 90;

}

else

{

orientation = 0;

}

//调用转屏事件

screenOrientationEvent();

innerWidthTmp = iw;

}

}

catch(e){alert(e);};

//间隔固定事件检查是否转屏,默认500毫秒

setTimeout("screenOrientationListener()",500);

}

//启动横竖屏事件监听

screenOrientationListener();

</script>

<body onload="screenOrientationEvent()">

<input id="change" type="text" value=""/>

</body>

</html>

  

移动端横屏(beta)

原文:http://www.cnblogs.com/moustache/p/5497132.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!