var testPhoto = new Image();
testPhoto.src = "http://plan9.bell-labs.com/plan9/img/9logo.jpg"
testPhoto.className = "pulse";然后:
topSlice.drawImage(testPhoto, 100, 200, 40, 40);在绘制图像后,脉动效应似乎不起作用,我应该如何修复这个问题?我遵循本教程的脉动效果。
发布于 2016-06-10 21:07:02
您可以使用Window.requestAnimationFrame代替,并使用混合模式/α混合:
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
image = new Image();
image.src = "http://plan9.bell-labs.com/plan9/img/9logo.jpg";
function update(timestamp) {
context.clearRect(0, 0, canvas.width, canvas.height);
context.globalAlpha = Math.sin(timestamp/100) * 0.5 + 0.5;
context.drawImage(image, 0, 0);
window.requestAnimationFrame(update);
}
window.requestAnimationFrame(update);<canvas id="canvas"></canvas>
https://stackoverflow.com/questions/37756500
复制相似问题