在移动应用中,有时要判断用户把设备竖向变成横向时,页面必须做出必须的调整,在
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() {
//在这里编写字体,样式,颜色等的改变
}



相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-11
  • 2022-02-17
猜你喜欢
  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
相关资源
相似解决方案