JavaScript控制多张图片循环播放(淡入淡出效果)

  1. <style>
  2. .imgShow{
  3.     font-size: 12px;
  4.     background-color: #B0C6CE;
  5.     text-align: center;
  6.     vertical-align: middle;
  7.     display: table-caption;
  8.     border-top-width: thin;
  9.     border-right-width: thin;
  10.     border-bottom-width: thin;
  11.     border-left-width: thin;
  12.     border-top-style: solid;
  13.     border-right-style: solid;
  14.     border-bottom-style: solid;
  15.     border-left-style: solid;
  16.     position:absolute;
  17.     width:400px;
  18.     height:300px;
  19. }
  20. .imgHide{
  21.     font-size: 12px;
  22.     background-color: #B0C6CE;
  23.     text-align: center;
  24.     vertical-align: middle;
  25.     display: table-caption;
  26.     border-top-width: thin;
  27.     border-right-width: thin;
  28.     border-bottom-width: thin;
  29.     border-left-width: thin;
  30.     border-top-style: solid;
  31.     border-right-style: solid;
  32.     border-bottom-style: solid;
  33.     border-left-style: solid;
  34.     position:absolute;
  35.     filter:alpha(opacity=0);
  36.     opacity:0.00;
  37.     width:400px;
  38.     height:300px;
  39. }
  40. </style>
  41. <script>
  42.     var hideTime=null;
  43.     var hide=100;//过滤镜初始值,IE
  44.     var hideFF=1.0;//过滤镜初始值,FF
  45.     var show=0;
  46.     var showFF=0.00;
  47.     var imgShow=1;
  48.     var imgSrcArray=new Array("https://p-blog.csdn.net/images/p_blog_csdn_net/lip009/EntryImages/20080726/0001.jpg","https://p-blog.csdn.net/images/p_blog_csdn_net/lip009/EntryImages/20080726/0004.jpg","https://p-blog.csdn.net/images/p_blog_csdn_net/lip009/EntryImages/20080726/0005.jpg");
  49.     function hideObject(hideImage,showImage){
  50.         try{
  51.             hidehide=hide-1;
  52.             hideFFhideFF=hideFF-0.01;
  53.             showshow=show+1;
  54.             showFFshowFF=showFF+0.01;
  55.             hideImage.style.filter="alpha(opacity="+hide+")";
  56.             hideImage.style.opacity=hideFF+"";/*FF兼容*/
  57.             //hideImage.style.-moz-opacity=hideFF+"";
  58.             showImage.style.filter="alpha(opacity="+show+")";
  59.             showImage.style.opacity=showFF+"";/*FF兼容*/
  60.             if(hide<=0){
  61.                 showImage.style.filter="alpha(opacity=100)";
  62.                 showImage.style.opacity=1.0;/*FF兼容*/
  63.                 window.clearInterval(hideTime);
  64.                 hideImage.style.display="none";
  65.                 window.setTimeout(changeImage,1000);
  66.             }
  67.         }catch(e){
  68.             window.clearInterval(hideTime);
  69.         }       
  70.     }
  71.     function changeImage(){
  72.         hide=100;
  73.         hideFF=1.0;
  74.         show=0;
  75.         showFF=0.0;
  76.         imgShow++;
  77.         if(imgShow>imgSrcArray.length){
  78.             imgShow=1;
  79.         }
  80.         var img1=document.getElementById("img1");
  81.         var img2=document.getElementById("img2");
  82.         var imageShow,imageHide;
  83.         if(img1.style.display=="none"){
  84.             img1.className="imgHide";
  85.             img2.className="imgShow";
  86.             img1.style.display="";
  87.             img1.src=imgSrcArray[imgShow-1];
  88.             imageShow=img1;
  89.             imageHide=img2;
  90.         }else{
  91.             img2.className="imgHide";
  92.             img1.className="imgShow";
  93.             img2.style.display="";
  94.             img2.src=imgSrcArray[imgShow-1];
  95.             imageShow=img2;
  96.             imageHide=img1;
  97.         }
  98.         
  99.         hideTime=window.setInterval(function(){hideObject(imageHide,imageShow);},20);
  100.     }
  101. </script>
  102. <img class="imgShow" id="img1" src="/image/1.jpg">
  103. <img class="imgHide" id="img2" src="/image/2.jpg">
  104. <pre></pre>
http://blog.csdn.net/lip009/archive/2008/07/26/2712344.aspx


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值