Save/restore background area of HTML5 Canvas

前端 未结 3 1993
攒了一身酷
攒了一身酷 2020-12-10 20:41

I am using HTML5 canvas as follows:

  1. Display an image that fills the canvas area.
  2. Display a black text label over the image.
  3. On click of the t
3条回答
  •  轮回少年
    2020-12-10 20:41

    function draw(e){
        ctx.drawImage(img, 0, 0);
        if(e){
            ctx.fillStyle='red';
            ctx.fillRect(5, 5, 50, 15);
            ctx.fillStyle='white';
        }else{
            ctx.fillStyle='black';
        }
        ctx.fillText('Label', 10, 17);
    }
    draw();
    document.onclick=draw;
    

提交回复
热议问题