2012-07-13 95 views
0

我正在使用以下腳本來生成圖像動畫。Javascript圖像動畫無法在Firefox或Internet Explorer中工作

它可以在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> 

不,我不能在其他瀏覽器的功能... 你能幫我嗎? 感謝

+1

爲什麼而不是'document.getElementById('centro')。src'而不是'document.images.centro' Coz'document.images'返回一個'HTML Collection'我真的不知道'document.images.id'是如何爲你工作的。可能是一些鉻優化。不要相信它跨瀏覽器 – Tamil 2012-07-13 13:02:00

+0

我做了開關,但仍然是相同的。 – Bcl00 2012-07-13 13:27:51

+0

其實發生了什麼?你能看到控制檯中的任何JavaScript錯誤?嘗試在鉻和F12 F12。如果沒有錯誤,那麼PLZ也會提及你能夠看到btwn chrome和firefox的區別 – Tamil 2012-07-13 13:33:47

回答

1

This是你相同的代碼工作版本的Chrome + Firefox的測試

setTimeout接受的第一個參數作爲參考的功能。所以,我剛剛將tempor=setTimeout("boucle_images()",tiempo)更換爲tempor=setTimeout(boucle_images, tiempo)。始終遵循這個怎麼把它保存一個eval

document.images返回HTML Collection,您可以訪問諸如數組[但它不是一個數組],但不喜歡document.image.centros [ATLEAST跨瀏覽器]因此我把它固定到document.getElementById('centros')

+0

@ Bcl00你還面臨一些問題嗎? – Tamil 2012-07-13 14:13:13

+0

當然,所有的解決方案都無法在所有瀏覽器中使用。否則Seeketh。感謝suguerencias。一聲問候 – Bcl00 2012-07-13 15:17:46

相關問題