简体   繁体   English

Windows Phone 8 Javascript画布不在整个页面上

[英]Windows Phone 8 Javascript canvas not on whole page

i'm creating an Windows Phone8 Javascript application. 我正在创建Windows Phone8 Javascript应用程序。

But I have one problem that i can't solve. 但是我有一个我无法解决的问题。

I'm working with a canvas, but the canvas is in portrait mode only 1/4 of my screen... (Developping on my Nokia Lumia 520) 我正在使用画布,但是画布处于纵向模式,仅占屏幕的1/4 ...(在诺基亚Lumia 520上开发)

Width and height of my canvas are: 我的画布的宽度和高度是:

canvas.width = window.innerWidth; //480
canvas.height = window.innerHeight; //800

My CSS: 我的CSS:

* { margin:0; padding:0; } /* to remove the top and left whitespace */
html, body { width:100%; height:100%; } /* just to be sure these are full screen*/
@media screen and (-ms-view-state: fullscreen-landscape) {
}
@media screen and (-ms-view-state: filled) {
}
@media screen and (-ms-view-state: snapped) {
}
@media screen and (-ms-view-state: fullscreen-portrait) {
}

My XAML: 我的XAML:

<Grid x:Name="LayoutRoot" Background="Transparent">
    <phone:WebBrowser x:Name="Browser"
                      Loaded="Browser_Loaded"
                      NavigationFailed="Browser_NavigationFailed"
                      IsScriptEnabled="True"
                      />
</Grid>

The Loaded event: 已加载事件:

private void Browser_Loaded(object sender, RoutedEventArgs e)
    {
        // Add your URL here
        Browser.Navigate(new Uri(MainUri, UriKind.Relative));
    }

Anyone any idea what i'm missing to use my canvas on the whole page? 任何人都知道我在整个页面上使用我的画布所缺少的吗?

This seems to work: 这似乎可行:

window.devicePixelRatio = window.devicePixelRatio || window.screen.availWidth / document.documentElement.clientWidth;

W = (window.innerWidth / window.devicePixelRatio); // Window's width
H = (window.innerHeight / window.devicePixelRatio); // Window's height

canvas.width = W;
canvas.height = H;

One remark: It works in portrait but not in landscape ... 备注:它可以在人像模式下使用,但不能在风景下...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM