<!DOCTYPE html5>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS3-Canvas画布(渐变)</title>
<script>
window.onload=function () {

var canvas=document.getElementById("canvas");//获取canvas对象
var ctx=canvas.getContext("2d"); //创建二维的绘图上下文对象
var gra=ctx.createLinearGradient(0,0,200,200);// 创建渐变对象 并且规定渐变填充的方向
//坐标(0,0)到(200,200)
gra.addColorStop(0,"lightpink");
gra.addColorStop(0.5,"lightblue");
gra.addColorStop(1,"lightgreen");
ctx.fillStyle=gra;//gra渐变对象 通常作为 fillStyle或者strokeStyle的属性值
ctx.fillRect(50,50,200,200); //开始坐标为(50,50) 宽度为200 有填充的矩形

}

</script>
</head>
<body>
<h2>Canvas画布(渐变)</h2>
<canvas >
浏览器不支持canvas
</canvas>
</body>
</html>

相关文章:

  • 2021-07-25
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-12-04
  • 2021-12-12
相关资源
相似解决方案