src
在侦听器之后设置.onload
,这样它无论如何都会触发。
var curvedArrow = new Image();
curvedArrow.addEventListener('load', function() {
context.drawImage(curvedArrow, 15, 45, 35, 30);
});
curvedArrow.src = "img/curvedArrow.png";
然后您可以使用间隔和globalAlpha淡入图像:
var curvedArrow = new Image();
curvedArrow.addEventListener('load', function() {
context.globalAlpha = 0;
var imgFadeInter = setInterval(function(){
clearContext(); // a function that clears the canvas
context.globalAlpha += 0.01;
context.drawImage(curvedArrow, 15, 45, 35, 30);
if(context.globalAlpha == 1){
clearInterval(imgFadeInter);
}
}, 16); // 16ms because jQuery says so
});
curvedArrow.src = "img/curvedArrow.png";