<!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