# Canvas Resize problem ?

**URL:** <https://forum.kirupa.com/t/canvas-resize-problem/634389>\
**Category:** programming\
**Created:** [March 25, 2016, 1:53am UTC](https://forum.kirupa.com/t/canvas-resize-problem/634389 "2016-03-25T01:53:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)\
**Post date:** [March 25, 2016, 1:53am UTC](https://forum.kirupa.com/t/canvas-resize-problem/634389/1 "2016-03-25T01:53:35Z")

</div>

Hi Kirupa ,  
I having trouble with ‘resizecanvas’.  
I am using quick.js .  
So far , the only way I can get canvas to resize correctly is by ‘location.reload();’ .  
See:  
[http://liesandcowpies.com/quickjs/BenghaziGame.html](http://liesandcowpies.com/quickjs/BenghaziGame.html)  
.html [pastebin.com/jPaFjcWk](http://pastebin.com/jPaFjcWk)  
.js [pastebin.com/xLcM9G4n](http://pastebin.com/xLcM9G4n)

I tried the following code from your article:  
See:  
[http://liesandcowpies.com/quickjs/BenghaziGame-kirupa.html](http://liesandcowpies.com/quickjs/BenghaziGame-kirupa.html)  
.html [pastebin.com/BfBE7NUW](http://pastebin.com/BfBE7NUW)  
.js [pastebin.com/Qc04CEGt](http://pastebin.com/Qc04CEGt)  
quick.js [pastebin.com/Gzqef5fu](http://pastebin.com/Gzqef5fu)

What happens below is that the canvas size is correct ,  
but instead of aligned in center , it displays on screen left .  
[liesandcowpies.com/quickjs/BenghaziGame-kirupa.html](http://liesandcowpies.com/quickjs/BenghaziGame-kirupa.html)  
Is there a different approach I can use ?

Thanks…

@ line 250 ( [pastebin.com/Qc04CEGt](http://pastebin.com/Qc04CEGt) ) :

```
window.addEventListener('resize', resizeCanvas, false);
function resizeCanvas () {
var myCanvas = document.getElementById('canvas');
// canvasDiv = canvasDiv.align = 'center';
// myCanvas.width = document.documentElement.innerWidth; // .inner* = Black Screen
 myCanvas.width = document.documentElement.clientWidth; // .client* = bad canvas align
 myCanvas.height = document.documentElement.clientHeight; // .client* = bad canvas align
// myCanvas.height = document.documentElement.innerHeight; // .inner* = Black Screen
      Quick.setAutoScale(false);
      Quick.setKeepAspect(true);
}	//
```

---

<div class="post-metadata">

**Author:** ![kirupa](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kirupa/32/11616_2.png) [@kirupa](https://forum.kirupa.com/u/kirupa)\
**Post date:** [March 27, 2016, 12:47am UTC](https://forum.kirupa.com/t/canvas-resize-problem/634389/2 "2016-03-27T00:47:53Z")

</div>

Hi, vmars!  
Did you fix the problem? From looking at this link ([http://liesandcowpies.com/quickjs/BenghaziGame-kirupa.html](http://liesandcowpies.com/quickjs/BenghaziGame-kirupa.html)), it seems centered on the screen 🙂

Cheers,  
Kirupa

---

<div class="post-metadata">

**Author:** ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)\
**Post date:** [March 27, 2016, 10:44pm UTC](https://forum.kirupa.com/t/canvas-resize-problem/634389/3 "2016-03-27T22:44:10Z")

</div>

Thanks Kirupa ,  
I tried both IE and Chrome .  
This one works fine:  
[http://liesandcowpies.com/quickjs/BenghaziGame.html](http://liesandcowpies.com/quickjs/BenghaziGame.html)

This one starts off ok , but hit the maximize-btn and restore-down  
back and forth a few times ; Each subsequent time is is gameCanvas get skewed to Left .  
[http://liesandcowpies.com/quickjs/BenghaziGame-kirupa.html](http://liesandcowpies.com/quickjs/BenghaziGame-kirupa.html)

Cheers vmars
