<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml;charset=UTF-8" />
<meta name="viewport" content="width=device-width" />
<title>手机横、竖屏事件</title>
<script language="javascript" type="text/javascript">
//屏幕方向标识,0横屏,其他值竖屏
var orientation=0;
//转屏事件,内部功能可以自定义
function screenOrientationEvent(){
if(orientation == 0)document.getElementById("change").value="竖";
else document.getElementById("change").value="横";
}
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>
</head>
<body onload="screenOrientationEvent()">
<input id="change" type="text" value=""/>
</body>
</html>

原文地址

http://www.dewen.io/q/8694/js%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E7%BD%91%E9%A1%B5%E6%A8%AA%E5%B1%8F%E5%92%8C%E7%AB%96%E5%B1%8F%E5%88%87%E6%8D%A2

最新文章

  1. jQuery checkbox的全选与反选
  2. 99%的人都理解错了HTTP中GET与POST的区别(转载
  3. Ionic 的 ng-class 在聊天功能上面的巧妙运用
  4. Android控件颜色设置为透明
  5. 关于selenium 3.0 + python 3.5中多层框架或窗口的定位driver.switch_to_frame()
  6. HDU5772 String problem(最大权闭合子图)
  7. 实用笔记-EF中直接运行SQL命令
  8. Mysql去除重复
  9. HDU 2222 Keywords Search(AC自动机模板题)
  10. Palindrome Partitioning——LeetCode
  11. [转载]CTO和技术总监区别
  12. gcc代码反汇编查看内存分布[1]: gcc
  13. CString Format 乱码问题
  14. 设计模式之前奏(UML类图)
  15. 浅谈CSS3动画的凌波微步--steps()
  16. js原生实现抽奖活动(方形非圆盘)
  17. [Python] timeit测试代码运行效率
  18. python数据类型及基本运算符
  19. Tomcat权威指南-读书摘要系列10
  20. JAVA 基础基本语法---常量与变量

热门文章

  1. 粗谈CGI
  2. 转:基于HTTP协议的轻量级开源简单队列服务:HTTPSQS
  3. [Fw]人和人之间在八小时之外的差别
  4. js 实现 di
  5. 协程coroutine
  6. -_-#【jQuery插件】Spinner 数字选择器
  7. 数据结构(线段树):Educational Codeforces Round 6 620E. New Year Tree
  8. 检测CPU是否支持虚拟化
  9. python关键字、转义符和字符串格式化
  10. java MessageFormat 应用 和 疑惑