2012-03-23 37 views
1

我很喜欢AppMobi XDK,并希望根据屏幕分辨率在不同的设备上应用一些样式。问题是我无法确定我的任何模拟设备的宽度和高度。请帮助确定AppMobi中的宽度和高度XDK

回答

2

您可以根据window.innerHeight和window.innerWidth获取大小。

XDK中存在一个问题,它在appMobi.device.ready事件触发后300ms内无法使用。

+0

谢谢,你的评论我解决了我的问题:) – 2013-04-05 21:51:59

0

从Ian评论它需要300ms后appMobi.device.ready触发。

在index.html文件中,只需在onDeviceReady函数内添加setTimeout即可。

var onDeviceReady=function(){ 
    //Size the display to 768px by 1024px 
    // AppMobi.display.useViewport(768,1024); 
    //hide splash screen 
    AppMobi.device.hideSplashScreen(); 

    setTimeout(setDisplayScreen, 300); 

}; 

在我的情况下,我只是想在页面的底部有脚注,我已经把它设置在PX。

function setDisplayScreen(){ 
    var dHeight = window.innerHeight; 
    document.getElementById("footer").style.top = dHeight - 70 + "px"; 

} 

它工作得很好。 在页脚出现之前有一小段延迟,但这并不坏。

0

问题是设备准备就绪时窗口高度不正确。这种精细工作对我来说:

VAR onDeviceReady =函数(){

intel.xdk.device.setRotateOrientation("any"); 
intel.xdk.device.setAutoRotate(true); 

setTimeout(setDisplayScreen, 300); 

function setDisplayScreen() { 
    var dHeight = window.innerHeight; 
     $('body').css('height', dHeight) 
    intel.xdk.device.hideSplashScreen();  

}  

};