canvas描绘渐变的矩形

时间:2023-03-10 01:30:19
canvas描绘渐变的矩形
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>渐变的矩形</title>
<script>
window.onload = function(){
var c = document.getElementById('c');
var ctx = c.getContext('2d');
//创建线型渐变对象
var jb = ctx.createLinearGradient(,,,);
jb.addColorStop(,'red');
jb.addColorStop(.,'green');
jb.addColorStop(.,'orange');
jb.addColorStop(,'blue');
ctx.fillStyle = jb;
ctx.fillRect(,,,); //x起点, y起点, x终点, y终点
}
</script>
</head>
<body>
<canvas id="c" width="" height="" ></canvas>
</body>
</html>