使一个矩形闪烁

时间:2018-05-12 10:07:28

标签: javascript html5 canvas

如何在HTML Canvas中闪烁(闪烁)矩形形状?

  
function Addrect() {
var red = new fabric.Rect({top: 300,
left: 100,
top: 800,
width: 350,
height: 350,
cornerSize: 40,
fill: 'green'
});
canvas.add(red);
}

Merciàvous;)

1 个答案:

答案 0 :(得分:0)

这里是一个选择:

const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');

let counter = 0;
setInterval(function() {
    context.fillStyle = (counter % 2 === 0) ? 'blue' : 'white';
    context.fillRect(10, 10, 80, 80);
    counter++;
}, 1000);
#canvas {
    width: 100px;
    height: 100px;
}
<canvas id="canvas"></canvas>