HTML canvas shadowOffsetY attribute

Definition and usage

shadowOffsetY The property sets or returns the vertical distance between the shape and the shadow.

  • shadowOffsetY=0 Indicates that the shadow is directly below the shape
  • shadowOffsetY=20 Indicates that the shadow is 20 pixels below the shape's top position
  • shadowOffsetY=-20 Indicates that the shadow is 20 pixels above the shape's top position

Tip:To adjust the horizontal position of the shape's distance, use shadowOffsetX Properties.

Example

Draw a rectangle with a shadow offset 20 pixels downwards (from the top position of the rectangle):

Your browser does not support the canvas tag.

JavaScript:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.shadowBlur=10;
ctx.shadowOffsetY=20;
ctx.shadowColor="black";
ctx.fillStyle="blue";
ctx.fillRect(20,20,100,80);

亲自试一试

语法

context.shadowOffsetY=number;

属性值

描述
number 正值或负值,定义阴影与形状的垂直距离。

技术细节

默认值: 0

浏览器支持

表中的数字注明了首个完全支持该属性的浏览器版本。

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
4.0 9.0 3.6 4.0 10.1

注释:Internet Explorer 8 以及更早的版本不支持 <canvas> 元素。