0
a=(canvas.width-70)/2 how is the value became 115 canvas is 900px by 500px is there a logic or a rule in the javascript canvas
11 odpowiedzi
+ 2
Your code?
+ 2
where did you specify your canvas width?
+ 2
Canvas width and height are better use inline attribute to set
+ 1
Try using canvas.style.width
canvas.width is the HTML attribute.
canvas.style.width is the CSS property.
The default width attribute of a canvas element is typically 300px.
(300 - 70)/2 = 115
So that's why you get 115.
Does this fix the problem? Because I know something else you might try.
0
<html>
<canvas id="canvas"></canvas>
<script>
a = document.getElementById("canvas");
var b =(a.width - 70) /2;
document.write(b, "<br>");
document.write(a.width);
</script>
</html>
0
well this is funny.. but i did it in css
0
oh...it looks better when I put the width and height inside the canvas tag
0
haha I noticed that a while ago....thanks..
0
So it's working now?
0
no...im just trying to study some code for better understanding of the logic
0
Its better add that set width and height like html attribute its DIFFERENT on set in css on canvas.
If you set only css width/height you will get desidered size on screen BUT it will be resized from 300x150 and you will get sometimes a distorted canvas content.
In practice, if do you not want distorted content, set width/height in html