一、shadowColor:设置阴影颜色,默认值为 '#000'。与 shadowBlur 属性一块儿使用,来建立阴影。spa
1 context.fillStyle = '#0091db' 2 context.shadowColor = '#ff0000' 3 for (let i = 0; i < 10; i++) { 4 context.beginPath() 5 context.shadowBlur = 5 * (i + 1) 6 if (i < 5) { 7 context.fillRect(50 + 200 * i, 50, 100, 80) 8 } else { 9 context.fillRect(50 + 200 * (i - 5), 250, 100, 80) 10 } 11 }
二、shadowOffsetX和shadowOffsetY属性:定义阴影与形状的水平、垂直距离。3d
1 context.beginPath() 2 context.fillStyle = '#0091db' 3 context.shadowBlur = 5 4 context.shadowColor = '#000' 5 context.shadowOffsetX = 10 6 context.shadowOffsetY = -10 7 context.fillRect(50,50,100,80)