shadowOffsetY Property - Javascript Canvas Reference

Javascript examples for Canvas Reference:shadowOffsetY

Description

The shadowOffsetY property sets or gets the vertical distance of the shadow from the shape.

shadowOffsety = 0 starts the shadow right behind the shape while shadowOffsetY = 20 starts the shadow 20 pixels below the shape's top position.

JavaScript syntax

context.shadowOffsetY = number;

Property Values

Value Description
number A positive or negative number that defines the vertical distance of the shadow from the shape

Example

Draw a rectangle with a shadow placed 20 pixels below the rectangle's top position:

JavaScript:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="300" height="250" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.shadowBlur = 10;//from www  .  j a v a 2s  . c o m
ctx.shadowOffsetY = 20;
ctx.shadowColor = "black";
ctx.fillStyle = "red";
ctx.fillRect(20, 20, 100, 80);

</script>

</body>
</html>

Related Tutorials