Safari (v5 on Windows) seem to have some issues with left-over pixels (probably in the alpha channel but I didn't dig deep into it to verify this) and composite modes.
In any case, there are two ways to fix this:
Option 1: Clear canvas manually
Add a clearRect()
line to your code and it will work on Safari as well:
function start() {
/// make sure no values are left on canvas incl. alpha channel
ctx.clearRect(0, 0, 940,500);
ctx.drawImage(maskItem, maskItemX, maskItemY);
ctx.globalCompositeOperation = "source-in";
ctx.drawImage(maskItem, maskItemX, maskItemY);
ctx.drawImage(background, 0, 0, 940, 500);
ctx.globalCompositeOperation = "destination-atop";
ctx.drawImage(background2, 0, 0, 940, 500);
ctx.globalCompositeOperation = "source-over"; /// restore default comp. mode
}
Option 2: Set composite mode to copy
before redrawing
Set this at the beginning or at the end depending on what you do next, but for the fiddle placing it at the end will do the trick:
function start() {
ctx.drawImage(maskItem, maskItemX, maskItemY);
ctx.globalCompositeOperation = "source-in";
ctx.drawImage(maskItem, maskItemX, maskItemY);
ctx.drawImage(background, 0, 0, 940, 500);
ctx.globalCompositeOperation = "destination-atop";
ctx.drawImage(background2, 0, 0, 940, 500);
ctx.globalCompositeOperation = "copy";
}
Copy mode makes sure all pixels are cleared before drawing