我正在寻找创建一个简单的动画循环使用HTML画布。每条路径(或三角形)都是按顺序淡入,然后以相同的顺序淡出。我已经发现围绕动画制作动画的大量资源,但不能在动画中连续使用alpha动画,尤其不能动画动画。有任何想法吗?如何为一系列html画布路径的alpha设置动画效果?
免责声明:这是我第一次使用画布,并且我的JavaScript知识是低劣的。由于我使用的是相同的形状,因此我将弄清楚如何复制,旋转和翻译原始文档作为单独的学习。
更新1:跟踪我的进度,here is a link to my sandbox。
更新2:我改变了脚本的结构,让我更好地控制每个路径。
var elem = document.getElementById('loader');
if (elem && elem.getContext) {
var ctxYellow = elem.getContext('2d');
var ctxOrange = elem.getContext('2d');
var ctxRed = elem.getContext('2d');
var ctxViolet = elem.getContext('2d');
var ctxBlue = elem.getContext('2d');
// Yellow triangle
if (ctxYellow) {
ctxYellow.fillStyle = '#f5ab1c';
ctxYellow.beginPath();
ctxYellow.moveTo(150, 150);
ctxYellow.lineTo(20, 75);
ctxYellow.lineTo(150, 0);
ctxYellow.lineTo(150, 150);
ctxYellow.fill();
ctxYellow.closePath();
}
// Orange triangle
if (ctxOrange) {
ctxOrange.fillStyle = '#f26d23';
ctxOrange.beginPath();
ctxOrange.moveTo(150, 150);
ctxOrange.lineTo(150, 0);
ctxOrange.lineTo(280, 75);
ctxOrange.lineTo(150, 150);
ctxOrange.fill();
ctxOrange.closePath();
}
// Red triangle
if (ctxRed) {
ctxRed.fillStyle = '#cd1f44';
ctxRed.beginPath();
ctxRed.moveTo(150, 150);
ctxRed.lineTo(280, 75);
ctxRed.lineTo(280, 225);
ctxRed.lineTo(150, 150);
ctxRed.fill();
ctxRed.closePath();
}
// Violet triangle
if (ctxViolet) {
ctxViolet.fillStyle = '#851a54';
ctxViolet.beginPath();
ctxViolet.moveTo(150, 150);
ctxViolet.lineTo(280, 225);
ctxViolet.lineTo(150, 300);
ctxViolet.lineTo(150, 150);
ctxViolet.fill();
ctxViolet.closePath();
}
// Blue triangle
if (ctxBlue) {
ctxBlue.fillStyle = '#295a9c';
ctxBlue.beginPath();
ctxBlue.moveTo(150, 150);
ctxBlue.lineTo(150, 300);
ctxBlue.lineTo(20, 225);
ctxBlue.lineTo(150, 150);
ctxBlue.fill();
ctxBlue.closePath();
}
}
你试过'保存'/'加载'方法吗? – kirilloid 2012-03-10 18:23:45
我没有。但我不确定为什么我想要。 – 2012-03-10 23:25:28
如果你想动画,没有其他对象,那么你会用clearRect足够。否则,它们可能会有所帮助。 – kirilloid 2012-03-11 07:40:27