设置透明度
- globalAlpha: 取值 0 - 1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#canvas {
border: 1px solid #000;
}
</style>
</head>
<body>
<div>
<canvas id="canvas" width="600" height="600"></canvas>
</div>
<script>
var canvas = document.getElementById("canvas");
// 获取渲染上下文 getContext
var ctx = canvas.getContext("2d");
// 设置透明度
ctx.globalAlpha = 0.5;
ctx.fillStyle = "blue";
ctx.fillRect(0, 0, 100, 100);
</script>
</body>
</html>
裁剪 clip
<div>
<canvas id="canvas" width="600" height="600"></canvas>
</div>
<script>
var canvas = document.getElementById("canvas");
// 获取渲染上下文 getContext
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(300, 300, 150, 0, 2*Math.PI, false);
ctx.stroke();//描边
ctx.clip();
ctx.fillStyle = "red";
ctx.fillRec
</script>
后面后续添加学习记录