Home >Web Front-end >H5 Tutorial >Canvas needs to define width and height directly in the tag_html5 tutorial skills

Canvas needs to define width and height directly in the tag_html5 tutorial skills

WBOY
WBOYOriginal
2016-05-16 15:47:021277browse

In the past, when I used canvas to draw pictures, I always wrote the width and height directly in the canvas tag. There was no problem. However, I have never explored why the width and height should be written directly in the canvas tag, because this is the case in various examples. Written. Today Sir Wang raised a question: If the width and height are written in
< ;/head>

< ;/canvas>
<script><br> function draw() {<br> var canvas=document.getElementById('canvas');<br> var context=canvas.getContext('2d');<br> context.beginPath();<br> context.moveTo(20,20);<br> context.lineTo(200,100);<br> context.lineWidth=5;<br> context.stroke();<br> }<br></script>


1. Width: 400; Height: 300; Write directly in < Effect in canvas>:

2. Delete the width and height in , width: 400; height: 300; the effect of writing in