I would like to make a scanner effect over an image in canvas similar to the thread How to animate scanner effect line with canvas but when add image clearRECT deletes the image below
var x = 4,
y = 4,
speed = 1,
isBottom = false;
document.getElementById("canvas").innerHTML = "";
var canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
img = new Image();
img.src = imagetag.src;
img.onload = function() {
canvas.width = img.width/2;
canvas.height = img.height/2;
ctx.drawImage(img, 0, 0, img.width/2, img.height/2);
}
function draw(imagetag) {
img = new Image();
img.src = imagetag.src;
img.onload = function() {
canvas.width = img.width/2;
canvas.height = img.height/2;
ctx.drawImage(img, 0, 0, img.width/2, img.height/2);
}
ctx.fillStyle = '#07C';
ctx.lineCap = 'round';
ctx.shadowBlur = 18;
ctx.shadowColor = "#07C";
ctx.fillRect(x, y, 210, 10);
if (!isBottom && y < canvas.height - 14) y += speed;
else if (y === canvas.height - 14) isBottom = true;
if (isBottom && y > 4) y -= speed;
else if (y === 4) isBottom = false;
requestAnimationFrame(draw);
}
draw(imagetag);