<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>陰影</title>
<style>
canvas{
border:1px solid red;
}
</style>
<script>
window.onload = function(){
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
context.fillStyle = 'red';
// 添加陰影
// X和Y軸的陰影偏移
context.shadowOffsetX = -5;
context.shadowOffsetY = -5;
// 陰影顏色
context.shadowColor = 'blue';
// 陰影模糊距離
context.shadowBlur = 5;
context.fillRect(100,100,200,200);
context.fillRect(300,300,50,50);
}
</script>
</head>
<body>
<canvas id="canvas" width="400px" height="400px"></canvas>
</body>
</html>html