<html>
<body>
<h1>HTML5 Canvas</h1>
<canvas id="myCanvas" width="200" height="100" style="border:1px solid grey;"></canvas>
<script>
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
// 创建渐变:
const grd = ctx.createLinearGradient(0,0,200,0);
grd.addColorStop(0,"red");
grd.addColorStop(1,"white");
// 填充渐变:
ctx.fillStyle = grd;
ctx.fillRect(10,10,150,80);
</script>
</body>
</html>