在
移动应用中,有时要判断用户把
设备竖向变成横向时,页面必须做出必须的调整,在
apple系列的机器上,如ipad,iphone,i
touch等,有一个属性可以判断:
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() {
//在这里编写字体,样式,颜色等的改变
}