: .
, , script ( ).
requestAnimationFrame: https://developer.mozilla.org/de/docs/Web/API/window/requestAnimationFrame
$(document).ready(function() {
var canvas = document.getElementById("canvas"),
ctx = canvas.getContext("2d"),
cw = canvas.width,
ch = canvas.height;
var y = 0;
function rectangles() {
ctx.save();
ctx.clearRect(0, 0, cw, ch);
ctx.beginPath();
ctx.fillStyle = "#006847";
ctx.fillRect(0, 0, 200, 450);
ctx.closePath();
ctx.beginPath();
ctx.fillStyle = "#CE1126";
ctx.fillRect(400, 0, 200, 450);
ctx.closePath();
ctx.save();
y++;
ctx.beginPath();
ctx.fillRect(0, y, 200, 450);
ctx.closePath();
ctx.clearRect(0, 0, cw, ch);
if (y < 450)
requestAnimationFrame( rectangles );
}
setInterval(rectangles, 2000);
});