canvas画布画好的图形,怎么在图形中填充渐变颜色,急求!!
1个回答
展开全部
<canvas id=myCanvas1 width=500px height=500px></canvas>
<script>
var myCanvas = document.getElementById("myCanvas1");
var context = myCanvas.getContext("2d");
//颜色渐变
var canvasGra = context.createLinearGradient(0,0,0,500);
canvasGra.addColorStop(0,"rgba(255,0,0,0.2)");
canvasGra.addColorStop(0.25,"rgba(0,255,0,0.2)");
canvasGra.addColorStop(0.5,"rgba(0,0,255,0.2)");
canvasGra.addColorStop(0.75,"rgba(0,255,255,0.2)");
canvasGra.addColorStop(1,"rgba(255,255,255,0.2)");
context.fillStyle =canvasGra;//样式,颜色渐变
context.beginPath();
context.fillRect(0,0,500,500);
context.fill();
</script>
<script>
var myCanvas = document.getElementById("myCanvas1");
var context = myCanvas.getContext("2d");
//颜色渐变
var canvasGra = context.createLinearGradient(0,0,0,500);
canvasGra.addColorStop(0,"rgba(255,0,0,0.2)");
canvasGra.addColorStop(0.25,"rgba(0,255,0,0.2)");
canvasGra.addColorStop(0.5,"rgba(0,0,255,0.2)");
canvasGra.addColorStop(0.75,"rgba(0,255,255,0.2)");
canvasGra.addColorStop(1,"rgba(255,255,255,0.2)");
context.fillStyle =canvasGra;//样式,颜色渐变
context.beginPath();
context.fillRect(0,0,500,500);
context.fill();
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询