0

次のスクリプトを使用して、画像のアニメーションを生成しています。

Chrome では動作しますが、Firefox や Internet Explorer では動作しません ...

Javascript

var lista = new Array('image1.gif','image1.gif','image1.gif','image1.gif'); 
var tiempo = 500; 
var tempor = null; 
var pos=0; 
var i = 0; 

function boucle_images(){ 
        var nombre_total_images = 6; 
        document.images.centro.src = lista[i] 
        pos=i; 
        i++; 
        i%=nombre_total_images; 
        tempor=setTimeout("boucle_images()",tiempo); 

} 

function avanza(){ 

  if (pos==(lista.length-1)) 
      pos=0; 
  else 
  pos++; 
  document.images.centro.src = lista[pos] 

} 

function retroceso(){ 

  if (pos==0) 
      pos=(lista.length-1); 
  else 
  pos--; 
  document.images.centro.src = lista[pos] 
} 

function automat(){ 
tempor = setTimeout("boucle_images()", tiempo) 
} 

function parar(){ 
clearTimeout(tempor); 
} 

HTML

<table width="52%" border="0" align="center"> 
                <tr> 
                    <td height="482" colspan="2" align="right">
                        <img id="centro" src="imagenes/cargando2.gif" alt="" width="640" height="480" /></td> 
                </tr>
                <tr> 
                    <td align="center"><div class="div_ani_sat">
                        <a href="javascript:retroceso()"><img src="imagenes/atras.png" width="48" height="48" alt="" /></a>
                        <a href="javascript:avanza()"><img src="imagenes/adelante.png" width="48" height="48" alt="" /></a>
                        <a href="javascript:boucle_images()"><img src="imagenes/play.png" width="48" height="48" alt="" /></a>
                        <a href="javascript:parar()"><img src="imagenes/pause.png" width="48" height="48" alt="" /></a></div>
                    </td> 
                </tr> 
            </table> 

他のブラウザでは機能しないわけではありません...助けてもらえますか? ありがとう

4

1 に答える 1

1

これは、chrome + firefox でテストされた同じコードの動作バージョンです。

setTimeout関数への参照として最初の引数を受け入れます。だから、私はあなたtempor=setTimeout("boucle_images()",tiempo)をに置き換えましたtempor=setTimeout(boucle_images, tiempo)。常にこのcozに従ってください。evalが保存されます

document.imagesHTML Collection配列のようにアクセスできる [ただし、配列ではありません] を 返しますが、document.image.centros[少なくともブラウザ間] とは異なります。したがって、次のように修正しましたdocument.getElementById('centros')

于 2012-07-13T13:55:08.977 に答える