画像をゆっくりとフェードインするループ機能を作った。HTML5/Javascriptのタイムアウトで機能が終了しない
var ctx; // this is the canvas already defined
function nextPic(i)
{
trans = 1; //resets transparent var to 1
fadeloop('out'); //starts loop
ctx.clearRect(0, 0, canvas.width, canvas.height); //clears canvas, this doesn't work
alert("done"); //this doesn't work either
}
function fadeloop(f){ //loop that fades
if(f == 'out'){ //make sure it wants to shade out
setTimeout(function() { //timed delay for fading out
fadeImgOut(); //calls function to fade out by .01
if(trans>0.0){ //if faded out break out of loop
fadeloop('out'); //if not restart function
}
},10);
}
}
function fadeImgOut(){ //function that fades out
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img,0,0);
ctx.globalAlpha = trans;
trans = trans - .01;
}
ボタンは、nextpicを呼び出します。それはゆっくりとイメージを透明化し、別のイメージにフェードインします。今は、トランス= .01までイメージをフェードアウトします。アラート(「完了」)やキャンバスのリセットを継続しません。私は何度もそれを見て、何をすべきか分かりません。
あなたがウェブでエラーを取得していますインスペクタ?私はアラート(「完了」)が発砲していない場合、スクリプトが何らかの理由でクラッシュしていると推測しています。 –
canvas.width&canvas.heightはどこで定義しますか? –
また、今どこで 'trans'を宣言しているのかは、各関数のローカル宣言に 'trans'があるように見えますが、ctxに対して行ったように、関数外のtrans宣言は表示されません。 –