繁体   English   中英

Javascript图像动画在Firefox或Internet Explorer中不起作用

[英]Javascript Image Animation does not work in Firefox or Internet Explorer

我正在使用以下脚本来生成图像的动画。

它适用于Chrome,但不适用于Firefox或Internet Explorer ...

Java脚本

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> 

并非我无法在其他浏览器中运行...能帮上忙吗? 谢谢

是您在chrome + firefox中测试过的相同代码的有效版本

setTimeout接受第一个参数作为对函数的引用。 因此,我只是将您的tempor=setTimeout("boucle_images()",tiempo)替换为tempor=setTimeout(boucle_images, tiempo) 始终遵循此原因,可以节省评估

document.images返回一个HTML Collection ,您可以像访问数组一样访问它[但不是数组],但是可以像访问document.image.centros一样访问[至少在浏览器中访问]因此,我将其固定为document.getElementById('centros')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM