js 判断手机横竖屏的实现方法(不依赖任何其他库)
2017-08-17 14:20
435 查看
<!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.net.cn/q/8694/
相关文章推荐
- JS判断移动设备最佳方法 并实现跳转至手机版网页
- JS判断是否手机或pad访问实现方法
- JS判断是否手机或pad访问实现方法
- JS判断移动设备最佳方法 并实现跳转至手机版网页
- js,php实现用ua判断手机,ipad,pc浏览器访问网页不同尺寸页
- 用于deeplink的js方法(判断手机是否安装app)
- js判断手机和pc端选择不同执行事件的方法
- Android实现判断手机未接来电及处理方法
- JS判断安卓手机是否装了某个app方法
- js手机横竖屏判断
- JS实现判断滚动条滚到页面底部并执行事件的方法
- 由于设计页面需要,要把两个并排显示的 div 实现一样高的效果, n 行 n 列布局,每列高度(事先并不能确定哪列的高度)相同,每个设计师追求的目标。方法有以下几种: 1 JS 实现(判断 2 个 d
- js判断手机浏览器操作系统和微信浏览器的方法
- 不依赖Flash和任何JS库实现文本复制与剪切附源码下载
- [分享黑科技]纯js突破localstorage存储上线,远程抓取图片,并转码base64保存本地,最终实现整个网站所有静态资源离线到用户手机效果却不依赖浏览器的缓存机制,单页应用最新黑科技
- js判断手机和pc端选择不同执行事件的方法
- js中判断对象是否为空的三种实现方法
- 纯JS实现的3D标签云,不依赖任何第三方库,支持移动页面
- JS实现判断碰撞的方法
- js中判断对象是否为空的三种实现方法