Javascript examples for Canvas Reference:shadowOffsetX
The shadowOffsetX property sets or gets the horizontal distance of the shadow from the shape.
shadowOffsetX = 0 indicates that the shadow is right behind the shape while shadowOffsetX = 20 starts the shadow 20 pixels to the right.
context.shadowOffsetX = number;
Value | Description |
---|---|
number | A positive or negative number that defines the horizontal distance of the shadow from the shape |
Draw a rectangle with a shadow placed 20 pixels to the right:
<!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 ww w .ja va 2 s. c o m ctx.shadowOffsetX = 20; ctx.shadowColor = "black"; ctx.fillStyle= "red"; ctx.fillRect(20, 20, 100, 80); </script> </body> </html>