js如何设置网页横屏和竖屏切换
2015-09-05 23:44
701 查看
<!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
相关文章推荐
- JavaScript语言精粹 笔记01 语法 对象
- js控制5秒后页面自动跳转
- JS relearn note Ⅰ
- 初学者对Servlet、JSP及Web容器之间关系的理解
- thinkjs
- JS正则表达式
- js算法:动态规划-多边形游戏
- Canvas制作排序算法演示动画
- 使用json存储结构化数据
- 学习javascript系列之变量
- emberjs之加载
- javascript实现继承的6种方式
- Javascript闭包演示【转】
- [连载]Tutorial series: learning how to write a 3D soft engine from scratch in C#, TypeScript or JavaScript[英]
- Js中的this和window.event.srcElement
- JavaScript学习笔记(一)
- Javascript高级程序设计——BOM(浏览器对象模型)
- jsp分页代码
- JSR 303 - Bean Validation 介绍及最佳实践
- Javascript中的事件绑定