属性值:
* shadowOffsetX: 阴影的水平偏移距离
* shadowOffsetY: 阴影的竖直偏移距离
* shadowBlur: 阴影的模糊效果,数字越大越模糊
* shadowColor: 阴影颜色
示例:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<canvas id="c2d">浏览器不支持canvas</canvas>
<script>
const canvas = document.querySelector('#c2d');
if(canvas.getContext) {
const ctx = canvas.getContext('2d');
// 设置阴影效果
ctx.shadowOffsetX = -7;
ctx.shadowOffsetY = 5;
ctx.shadowBlur = 3;
ctx.shadowColor = 'rgba(255,255,0,0.7)';
ctx.fillStyle = 'red';
ctx.fillRect(15,30,130,40);
}
</script>
</body>
</html>
```
![](https://upload-images.jianshu.io/upload_images/2789632-cabf3b134738f8e3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)