English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
shadowOffsetX is a Canvas 2D API describes the attribute that specifies the horizontal offset distance of the shadow.
Draw a shadow on the right2A rectangle starting at 0 pixels (from the left side of the blue rectangle):
HTML canvas shadowOffsetX attribute usage demonstration:
<!DOCTYPE html> <html> <head> <title>HTML canvas shadowOffsetX 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.shadowOffsetX=20; ctx.shadowColor="black"; ctx.fillStyle="blue"; ctx.fillRect(20,20,100,80); </script> </body> </html>Test to see ‹/›
IEFirefoxOperaChromeSafari
Internet Explorer 9Firefox, Opera, Chrome, and Safari support the shadowOffsetX attribute.
Note:Internet Explorer 8 and earlier versions do not support the <canvas> element.
The shadowOffsetX property sets or returns the horizontal distance between the shadow and the shape.
shadowOffsetX = 0 means the shadow is exactly behind the shape.
shadowOffsetX = 20 means the shadow starts from the left side of the shape to the right20 pixels.
shadowOffsetX = -20 means the shadow starts from the left side of the shape to the left20 pixels.
Tip:To adjust the vertical distance of the shadow from the shape, please use shadowOffsetY Attribute.
Default value: | 0 |
---|---|
JavaScript syntax: | context.shadowOffsetX=number; |
Value | Description |
---|---|
number | Positive or negative value, defines the horizontal distance of the shadow from the shape. |