现在的位置: 首页 > 综合 > 正文

在移动应用中判断横向和竖向方向的改变

2013年08月24日 ⁄ 综合 ⁄ 共 661字 ⁄ 字号 评论关闭
在移动应用中,有时要判断用户把设备竖向变成横向时,页面必须做出必须的调整,在

apple系列的机器上,如ipad,iphone,itouch等,有一个属性可以判断:

window.onorientationchange = detectOrientation;

function detectOrientation(){

if(typeof window.onorientationchange != 'undefined'){

if ( orientation == 0 ) {

//Do Something In Portrait Mode

}

else if ( orientation == 90 ) {

//Do Something In Landscape Mode

}

else if ( orientation == -90 ) {

//Do Something In Landscape Mode

}

else if ( orientation == 180 ) {

//Do Something In Landscape Mode

}

}

}

而在其他类型的移动设备上,则可能要花点心思了,要通过其长,宽的改变去判断了,用jquery其实也可以实现的,比如:

  $(document).ready(function(){

   if ( window.orientation != undefined )

     window.onorientationchange = updateView;

   else

     $(window).resize( updateView );

}

function updateView() {

//在这里编写字体,样式,颜色等的改变  

}

抱歉!评论已关闭.