HTML canvas shadowOffsetX attribute

Definition and Usage

shadowOffsetX Property settings or returns the horizontal distance between the shape and the shadow.

  • shadowOffsetX=0 Indicates that the shadow is directly below the shape
  • shadowOffsetX=20 Indicates that the shadow is 20 pixels to the right of the shape's left position
  • shadowOffsetX=-20 Indicates that the shadow is 20 pixels to the left of the shape's left position

Tip:To adjust the vertical position of the shape, use shadowOffsetY Properties.

Example

Draw a rectangle with a shadow offset 20 pixels to the right (from the rectangle's left position):

Your browser does not support the canvas tag.

JavaScript:

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);

Kokeile itse

Syntaksi

context.shadowOffsetX=number;

Ominaisuusarvo

Arvo Kuvaus
number Positiivinen tai negatiivinen arvo, joka määrittää varjon ja muodon horisontaalisen etäisyyden.

Tekninen yksityiskohta

Oletusarvo: 0

Selaimen tuki

Taulukossa olevat numerot osoittavat ensimmäisen version, joka tukee tätä ominaisuutta täysin.

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

Huomautus:Internet Explorer 8 ja aikaisemmat versiot eivät tue <canvas> -elementtiä.