If w is your width and h your height.
w/h is your ratio.
Now your page width is bigger or smaller.
Let's say your new width name is newW.
And you are searching newH.
To keep your ratio just do the math :
newH = newW / (w/h);
To get your width and height just use a document.getElementById("canvas").width/height
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…