-1

読み込まれた画像の合計に使用される非表示の div タグがあります。

<div id="ImagesLoaded">0</div>

画像ページが実行されると、8 つの画像が読み込まonloadれ、「ImagesLoaded」に 1 が追加されます。一部の画像は他の画像よりも大きい場合があるため、ページの読み込み時間は異なる場合があります。「ImagesLoaded」が 8 の場合、スクリプトを実行して画面を調整します。これは、画像のサイズと向きに基づいて行われます。

私が知りたいのはこれです: ロードした画像の数を 100 ミリ秒ごとにチェックするスクリプトをバックグラウンドで実行するにはどうすればよいですか? 8 枚の画像がある場合は、金額の確認を停止し、別のスクリプトを実行する必要があります。

何か案は?

4

2 に答える 2

4
 onLoad = "addOneToImagesLoaded();"

とjs:

 function addOneToImagesLoaded(){
      current_count = parseInt(getElementById('ImagesLoaded').innerHTML);
      current_count = current_count+1;
      getElementById('ImagesLoaded').innerHTML = current_count.toString();
      if (current_count == 8){
           YOUR LOGIC GOES HERE
      }
 }
于 2012-11-19T21:06:54.203 に答える
2

You can use setInterval:

var imageInterval = setInterval(checkingFunction, 100);

function checkingFunction()
{
    if (count == 8)
    {
         // do what you want to do
         clearInterval(imageInterval);
    }
}

Alternatively you could call a function like this in the onload handlers:

function imageLoaded()
{
     count++;
     if (count == 8)
     {
         // do what you want to do
     }
}

In both examples I'm using a global count variable rather than a div element to store the value.

于 2012-11-19T21:05:43.940 に答える