码迷,mamicode.com
首页 > 其他好文 > 详细

判断设备是否横屏

时间:2017-03-31 11:49:08      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:hone   idt   pos   property   nbsp   ken   function   window   osi   

css3
/* For portrait, we want the tool bar on top */ //横屏 @media screen and (orientation: portrait) { #toolbar { width: 100%; } } /* For landscape, we want the tool bar stick on the left */ //竖屏 @media screen and (orientation: landscape) { #toolbar { position: fixed; width: 2.65em; height: 100%; } p { margin-left: 2em; } li + li { margin-top: .5em; } }


js

 判断是横屏还是竖屏的方法:
  function orient() {
if (window.orientation == 90 || window.orientation == -90) {
//ipad、iphone竖屏;Andriod横屏
$("body").attr("class", "landscape");
orientation = ‘landscape‘;
return false;
}
else if (window.orientation == 0 || window.orientation == 180) {
//ipad、iphone横屏;Andriod竖屏
$("body").attr("class", "portrait");
orientation = ‘portrait‘;
return false;
}
}
//页面加载时调用
$(function(){
orient();
});
//用户变化屏幕方向时调用
$(window).bind( ‘orientationchange‘, function(e){
orient();
});
 

判断设备是否横屏

标签:hone   idt   pos   property   nbsp   ken   function   window   osi   

原文地址:http://www.cnblogs.com/XIE7654/p/6650521.html

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