HTML5 Canvas, shadowColor & shadowBlur

后端 未结 3 1704
抹茶落季
抹茶落季 2021-01-19 14:52

My question is regarding this shadowBlur feature used on the 2nd (outer) rectangle below. The shadowBlur feature is applied to every shape after this rectangle. (If

相关标签:
3条回答
  • 2021-01-19 15:00
        var canvas3=document.getElementById("myCanvas");
        var ctx3=canvas1.getContext("2d");
    

    change canvas1 to canvas3 in the second line. Your ctx3 is actually pointing to canvas1 which i think is wrong.

    0 讨论(0)
  • 2021-01-19 15:14

    Use either this:

    ctx.save();
      ctx.shadowColor="black";
      ctx.shadowBlur = 10;       
      ctx.strokeRect(45,45,210,110); 
    ctx.restore();
    

    Or this:

    ctx.shadowColor="black";
    ctx.shadowBlur = 10;       
    ctx.strokeRect(45,45,210,110); 
    ctx.shadowColor= undefined; 
    ctx.shadowBlur = undefined;       
    

    I am not sure about 'undefined' in second case - something to nullify/reset the value.

    0 讨论(0)
  • 2021-01-19 15:20

    You can also consider setting the shadow color to "transparent" instead of undefined or null. This also seems to do the trick.

    0 讨论(0)
提交回复
热议问题