码迷,mamicode.com
首页 > 移动开发 > 详细

移动端--判断横竖屏

时间:2017-09-13 17:18:12      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:dsc   bsp   object   logs   parent   body   lan   code   case   

(function(){
var supportOrientation = (typeof window.orientation === ‘number‘ &&
typeof window.onorientationchange === ‘object‘);
var init = function(){
var htmlNode = document.body.parentNode,
orientation;
var updateOrientation = function(){
if(supportOrientation){
orientation = window.orientation;
switch(orientation){
case 90:
case -90:
orientation = ‘landscape‘;
break;
default:
orientation = ‘portrait‘;
break;
}
}else{
orientation = (window.innerWidth > window.innerHeight) ? ‘landscape‘ : ‘portrait‘;
}
htmlNode.setAttribute(‘class‘,orientation);
};
if(supportOrientation){
window.addEventListener(‘orientationchange‘,updateOrientation,false);
}else{
//监听resize事件
window.addEventListener(‘resize‘,updateOrientation,false);
}
updateOrientation();
};
window.addEventListener(‘DOMContentLoaded‘,init,false);
})();

 

移动端--判断横竖屏

标签:dsc   bsp   object   logs   parent   body   lan   code   case   

原文地址:http://www.cnblogs.com/huangmin1992/p/7515595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!