您的位置:首页 > 其它

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

2013-07-01 16:25 316 查看
在移动应用中,有时要判断用户把设备竖向变成横向时,页面必须做出必须的调整,在
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() {
//在这里编写字体,样式,颜色等的改变
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: