javascript - canvas如何在几个同心圆上内部圆的边框颜色不被外部圆的内填充颜色覆盖,想实现如图所示效果
本文介绍了javascript - canvas如何在几个同心圆上内部圆的边框颜色不被外部圆的内填充颜色覆盖,想实现如图所示效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
我的代码如下,两种黑色都会将内部圆的边框覆盖掉
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var radius=10;
for(var a=0;a<3;a++){
ctx.beginPath();
ctx.arc(100,100,radius,0,Math.PI*2);
ctx.strokeStyle="red"
ctx.stroke()
ctx.fill()
ctx.closePath();
radius+=20
}
/*ctx.beginPath();
ctx.arc(100,100,10,0,Math.PI*2);
ctx.strokeStyle="green"
ctx.stroke()
ctx.fill()
ctx.closePath();
ctx.beginPath();![图片描述][1]
ctx.arc(100,100,30,0,Math.PI*2);
ctx.strokeStyle="green"
ctx.stroke()
ctx.fill()
ctx.closePath(); */
</script>
解决方案
先画外面再画里面,先后顺序理清楚了就好了
这篇关于javascript - canvas如何在几个同心圆上内部圆的边框颜色不被外部圆的内填充颜色覆盖,想实现如图所示效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文