English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML canvas shadowOffsetY attribute

shadowOffsetY is a Canvas 2The D API describes an attribute that specifies the vertical offset of the shadow.

HTML canvas Reference Manual

Online Example

Draw a shadow below the rectangle at the top2a rectangle at 0 pixels from the top:

Your browser does not support HTML5 canvas tag.

shadowOffsetY attribute usage:

<!DOCTYPE html>
<html>
<head>
<title>HTML canvas shadowOffsetY attribute usage (Basic Tutorial Website oldtoolbag.com)</<title>
</<head>
<body>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3>
Your browser does not support HTML5 canvas tag.
</canvas>
<script>
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.shadowBlur=10;
ctx.shadowOffsetY=20;
ctx.shadowColor="black";
ctx.fillStyle="red";
ctx.fillRect(20,20,100,80);
</script>
</body>
</html>
Test it out ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 9Firefox, Opera, Chrome, and Safari support the shadowOffsetY attribute.

Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.

Definition and Usage

The shadowOffsetY property sets or returns the vertical distance between the shadow and the shape.
shadowOffsety = 0 indicates that the shadow is exactly behind the shape.
shadowOffsetY = 20 indicates that the shadow starts below the top position of the shape20 pixels.
shadowOffsetY =-20 indicates that the shadow starts above the top position of the shape20 pixels.

Tip:To adjust the horizontal distance between the shadow and the shape, please use shadowOffsetX Attribute.

Default value:0
JavaScript Syntax:context.shadowOffsetY=number;

Attribute value

ValueDescription
numberPositive or negative value, defines the vertical distance between the shadow and the shape.
HTML canvas Reference Manual