2012-12-16 50 views
2

我只是想知道如何使Javascript Canvas響應90%的高度和100%的寬度。我曾嘗試過:使用百分比而不是畫布中的像素來調整高度和寬度

canvas.width = 100%; 
canvas.height = 90%; 

但它只是在我的IDE中出現語法錯誤,並且畫布不再呈現。 任何想法?

+0

http://stackoverflow.com/questions/2588181/canvas-is-stretch-when-using-css-but-normal-with-old-width-and-height-proper AND http://stackoverflow.com/questions/10750125/scaling-html5-canvas-width-preserving-wh-aspect-ratio –

回答

3

嘗試canvas.style.width = '100%';和類似的height

+0

Thanks @Kolink that works :) –

相關問題