私はこのコードを持っています:
var run_anim = "";
var anim_array = ["\animations\pic_1.gif",
"\animations\pic_2.gif",
"\animations\pic_3.gif",
"\animations\pic_4.gif"]
function changeBackgroundURL(elementId, backgroundURL){
run_anim = "false";
document.getElementById(elementId).style.background=backgroundURL;
}
function mouseover_anim(elementName){
run_anim = "true";
changeBackgroundURL(elementName,anim_array[0]);
while(run_anim=="true"){
setTimeout(function(){changeBackgroundURL(elementName,anim_array[1]) parameter = null},30);
setTimeout(function(){changeBackgroundURL(elementName,anim_array[2]) parameter = null},40);
setTimeout(function(){changeBackgroundURL(elementName,anim_array[3]) parameter = null},20);
}
}
私はこの行を実行しています:
<area shape="rect" coords="0,0,95,91"
onMouseOver="mouseover_anim('div_1')"
onMouseOut="changeBackground('div_1', 'pic_static.gif')">
実行すると、アプリケーションが多くの CPU を使用するため、ブラウザーを閉じる必要があります。while ループ (常に true) がホール システムをブロックしているように見えます (ただし、画像の変化は見られません)。また、ブラウザでのデバッグ中にエラー メッセージが表示されません。また、写真をプリロードしようとしましたが (コードは上に掲載されていません)、それでも機能しませんでした。
このコードは、while ループを無効にして、次のように長いタイムアウトを設定した場合にのみ機能します。
function mouseover_anim(elementName){
changeBackgroundURL(elementName,anim_array[0]);
setTimeout(function(){changeBackgroundURL(elementName,anim_array[1]) parameter = null},300);
setTimeout(function(){changeBackgroundURL(elementName,anim_array[2]) parameter = null},400);
setTimeout(function(){changeBackgroundURL(elementName,anim_array[3]) parameter = null},200);
}
Javascriptでループアニメーションや高速アニメーションを作成することは不可能ですか? または、それを行う方法について何か提案はありますか?