js實現圖片淡入淡出切換簡易效果_javascript技巧

來源:互聯網
上載者:User

本文執行個體為大家分享了js圖片淡入淡出切換詳細代碼,供大家參考,具體內容如下

<!DOCTYPE html><html>  <head>    <meta charset="UTF-8">    <title></title>    <style type="text/css">      *{padding: 0;margin: 0;}      ul{overflow: hidden;}      li{list-style: none;height: 30px;border: 1px solid #000;width: 100px;float: left;line-height: 30px;text-align: center;}      img{width:306px;opacity: 0;}      .active{background:yellow}    </style>            </head>  <body>    <ul>      <li>王寶強</li>      <li>馬蓉</li>      <li>宋吉</li>    </ul>    <img src=""/>  </body>  <script src="public.js"></script>    <script type="text/javascript">      var oLi=document.getElementsByTagName("li");      var oImg=document.getElementsByTagName("img")[0];      var arr=['img/wbb.jpg','img/wlp.jpg','img/qs.jpg']      var time=null;      var time1=null;             for(i=0;i<oLi.length;i++){        oLi[i].index=i;        oLi[i].onclick=function(){          for(i=0;i<oLi.length;i++){            oLi[i].className="";          }          this.className="active";          oImg.src=arr[this.index];                     var num=0;          var step=2;          clearInterval(time);          clearInterval(time1);          time = setInterval(function(){            num+=step;            if(num>=200){              num=200;              clearInterval(time);            }            oImg.style.opacity = num/200;          },20)           }      }           </script></html>

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.