一张图片,想叫他渐渐消失,然后换成另一个图片,但是效果出不来,我对javascript很生
写了段代码,问题在哪里,请行家看看head里面:
<script type="text/javascript" language="javascript">
   var a=100;
   var curImg=0;
   function ImgOnload()
   {   
  setTimeout("switchImage()",3000);   
  }
   function clearImage()
   {
   a- = 10;   
  img1.style="filter:alpha(opacity=a)";
   if(a>0)
   {   
  setTimeout("clearImage()",300)
   }   }
   function switchImage()
   {
   curImg++;
   img1.src="img/"+curImg+".jpg";  
  setTimeout("clearImage()",300)  
  if(curImg<6)
   {
   setTimeout("switchImage()",3000);
   }
   else
   {
   curImg=0;
   setTimeout("switchImage()",3000);
   }   
  }  
   
    
  </script>body里面:
<p><img id="img1" src="img/1.jpg" onload="ImgOnload()" /></p>

解决方案 »

  1.   

    img1.style="filter:alpha(opacity=" + a + ")";
      

  2.   

    a- = 10;   
     //img1.style="filter:alpha(opacity=a)";
    img1.style="filter:alpha(opacity=" + a + ")";
      

  3.   

    用JQ吧,fadeIn(“slow或fast或具体间隔值"),fadeOut(“slow或fast或具体间隔值"),使用简单,而且不象filter这样只有IE能用。
      

  4.   

    img1.style="filter:alpha(opacity=a)";
    这样写,那个a的值没有被计算出来。
    img1.style="filter:alpha(opacity=" + a + ")";这样写才对。