How to draw a rectangle with shadow on canvas in JavaScript

4 Answers

0 votes
<canvas id="canvas" width="1024" height="600"></canvas>
<script type="text/JavaScript">   

var ctx = document.getElementById('canvas').getContext('2d');

ctx.shadowColor = "black";
ctx.shadowBlur = 10;

ctx.fillStyle = "white";
ctx.fillRect(10, 10, 200, 100);

</script>

 



answered May 26, 2016 by avibootz
0 votes
<canvas id="canvas" width="1024" height="600"></canvas>
<script type="text/JavaScript">   

var ctx = document.getElementById('canvas').getContext('2d');

ctx.shadowColor = "blue";
ctx.shadowBlur = 7;

ctx.fillStyle = "white";
ctx.fillRect(10, 10, 150, 100);

</script>

 



answered May 26, 2016 by avibootz
0 votes
<canvas id="canvas" width="1024" height="600"></canvas>
<script type="text/JavaScript">   

var ctx = document.getElementById('canvas').getContext('2d');

ctx.shadowColor = "black";
ctx.shadowOffsetY = 7;
ctx.shadowOffsetX = 7;

ctx.fillStyle = "blue";
ctx.fillRect(10, 10, 150, 100);

</script>

 



answered May 27, 2016 by avibootz
0 votes
<canvas id="canvas" width="1024" height="600"></canvas>
<script type="text/JavaScript">   

var ctx = document.getElementById('canvas').getContext('2d');

ctx.shadowColor = "black";
ctx.shadowOffsetY = 7;
ctx.shadowBlur = 7;
                  
ctx.fillStyle = "blue";
ctx.fillRect(10, 10, 150, 100);

</script>

 



answered May 27, 2016 by avibootz
...