简体   繁体   English

有什么区别 <svg> 和 <canvas> 在给定的代码实现?

[英]What is the difference in <svg> and <canvas> implementation in given code?

 <body> <svg width="200" height="200"> <circle cx="100" cy="100" r="70" stroke-width="10" stroke="red" fill="green" /> </svg> <canvas id="canvas01" width="200" height="200"> </canvas> <script> var c = document.getElementById("canvas01"); var cx = c.getContext("2d"); cx.beginPath(); cx.arc(100,100,70,0,2*Math.PI); cx.lineWidth = 10; cx.strokeStyle = 'red'; cx.stroke(); cx.fillStyle = 'black'; cx.fill(); </script> </body> </html> 

I am missing something here while comparing basics of <svg> and <canvas> Why is the border width of the circles in output different? 在比较<svg><canvas>基础知识时,这里缺少某些内容为什么输出中的圆的边框宽度不同? Isn't the stroke-width="10" and cx.lineWidth = 10 supposed to give the equal border width? 是否应该将stroke-width="10"cx.lineWidth = 10赋予相等的边框宽度?

You fill after stroke -> overwrite half the stroke. 您在stroke之后fill ->覆盖描边的一半。

 <svg width="200" height="200" viewBox="0 0 200 200"> <circle cx="100" cy="100" r="70" stroke-width="10" stroke="red" fill="green" /> </svg> <canvas id="canvas01" width="200" height="200"></canvas> <script> var c = document.getElementById("canvas01"); var cx = c.getContext("2d"); cx.beginPath(); cx.arc(100,100,70,0,2*Math.PI); cx.lineWidth = 10; cx.strokeStyle = 'red'; cx.fillStyle = 'black'; cx.fill(); cx.stroke(); </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM