2016-11-30 79 views
3

我想在科尔多瓦找到设备高度?在科尔多瓦获取设备高度

pChart.chartHeight = 100; 

我可以写什么而不是100100应该是设备的高度。

+1

可能的重复:http://stackoverflow.com/questions/38086271/cordova-get-screen-width-and-height-on-device-ready-event –

+0

@ Rory McCrossan window.innerWidth does not work – diad

+0

你是阅读的问题,而不是检查答案:http://stackoverflow.com/a/38086846/519413 –

回答

0

试试这个。

var w = window.innerWidth 
|| document.documentElement.clientWidth 
|| document.body.clientWidth; 

var h = window.innerHeight 
|| document.documentElement.clientHeight 
|| document.body.clientHeight; 

alert(w +" - "+h); 
+0

不工作window.innerWidth当旋转屏幕 – diad

+0

其他条件应该工作。尝试document.documentElement.clientHeight – Navneeth

+0

我需要定向景观 – diad

1

使用.resize()

$(window).resize(function() { 
    alert($(window).height() + $(window).width); 
}); 
1

window.screen可以获取其宽度和高度的属性,但你也应该补充的像素密度,因为它可以在定向或不同设备之间改变。试试这个:

var physicalScreenHeight = window.screen.height * window.devicePixelRatio; 

productionChart.chartHeight = physicalScreenHeight; 

而且看看here以防万一你有更多的疑惑。