0
在以下示例中,如何執行以下HTML帆布梯度動畫
當我創建在createGradient函數的梯度,僅第一弧具有多個顏色,第二弧具有單一顏色
當animate函數被調用時,我想只改變一個指定的梯度,而不是所有的人都
function init() {
can = document.getElementById("can");
ctx = can.getContext("2d");
drawGradients();
var t=setTimeout("animate()",3000);
}
function drawGradients() {
var points = [[50,50,5, 50,50,50], [275,275,5, 275,275,50]];
for (var i=0; i < points.length; i ++) {
var cords = points[i];
createGradient (points[i]);
}
}
function createGradient(cds) {
var grad = ctx.createRadialGradient(cds[0],cds[1],cds[2],cds[3],cds[4],cds[5]);
grad.addColorStop(0, 'white');
grad.addColorStop(1, 'black');
ctx.fillStyle=grad;
ctx.arc(cds[3],cds[4], cds[5], 0, 2 * Math.PI);
ctx.fill();
}
function animate() {
var cds =[50,50,5, 50,50,50];
var grad = ctx.createRadialGradient(cds[0],cds[1],cds[2],cds[3],cds[4],cds[5]);
grad.addColorStop(0, 'white');
grad.addColorStop(1, 'blue');
ctx.fillStyle=grad;
ctx.arc(cds[3],cds[4], cds[5], 0, 2 * Math.PI);
ctx.fill();
}
</script>
很有可能完全無關的問題,但它通常是更好地做到'的setTimeout(動畫,3000)'不是'的setTimeout( 「動畫()」,3000)'因爲後者使用'eval'。 – icktoofay 2011-05-25 01:58:37