Resizing canvas, where's the problem?

I think this is the behavior you are trying to achieve. I refactored it so you only need to create one Image object (and changed the variable names to English so I could follow the code easier). Hopefully it's clear how the code works.

Feel free to ask in the comments if you have any questions about it. The body onload property will need to be changed to setupBackground() instead of draw() to work with this code function setupBackground() { var canvas = document. GetElementById('canvas'); var ctx = canvas.

GetContext('2d'); function draw() { canvas. Width = 0; canvas. Height = 0; var divHeight = div.

ScrollHeight; var divWidth = div. ScrollWidth; var yScale = divHeight / img. Height; var xScale = divWidth / img.

Width; var newImgHeight = img. Height * xScale; var newImgWidth = divWidth; if (divHeight >= newImgHeight) { newImgHeight = divHeight; newImgWidth = img. Width * yScale; } canvas.

Width = divWidth; canvas. Height = divHeight; ctx. DrawImage(img,0,0,newImgWidth,newImgHeight); } var img = new Image(); img.

Onload = function() { window. Onresize = draw; draw(); } img. Src = 'ad.

Jpg'; }.

I think this is the behavior you are trying to achieve. I refactored it so you only need to create one Image object (and changed the variable names to English so I could follow the code easier). Hopefully it's clear how the code works.

Feel free to ask in the comments if you have any questions about it. The body onload property will need to be changed to "setupBackground();" instead of "draw();" to work with this code. Function setupBackground() { var canvas = document.

GetElementById('canvas'); var ctx = canvas. GetContext('2d'); function draw() { canvas. Width = 0; canvas.

Height = 0; var divHeight = div. ScrollHeight; var divWidth = div. ScrollWidth; var yScale = divHeight / img.

Height; var xScale = divWidth / img. Width; var newImgHeight = img. Height * xScale; var newImgWidth = divWidth; if (divHeight >= newImgHeight) { newImgHeight = divHeight; newImgWidth = img.

Width * yScale; } canvas. Width = divWidth; canvas. Height = divHeight; ctx.

DrawImage(img,0,0,newImgWidth,newImgHeight); } var img = new Image(); img. Onload = function() { window. Onresize = draw; draw(); } img.

Src = 'ad. Jpg'; }.

As far as I know. You only want to make one call to getContext(). I didn't really analyze the code very much past this point though.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions