JavaScript圖片輪播,舉一反三

來源:互聯網
上載者:User

標籤:

圖片輪播,在一些購物網站上運用的不勝枚舉,下面簡單介紹一片輪播的實現。

 

<!doctype html><html lang="en"> <head>  <meta charset="UTF-8">  <meta name="Generator" content="EditPlus®">  <meta name="Author" content="">  <meta name="Keywords" content="">  <meta name="Description" content="">  <title>圖片亂撥</title>  <style type="text/css">  .body{    width:524px;    border:solid 1px #666;    margin-left:auto;    margin-right:auto;    }  .bg{        background-color:#E0E0E0;        height:20px;        border-top:solid 1px #B4B4B4;        }    .number{        font-size: 14px;        font-weight: bold;        color: #FFF;        background-color: #9E2E07;        display: block;        border: 1px solid #FFF;        width:18px;        height:18px;        text-align: center;        margin-left:10px;        cursor:pointer;        float:left;        }    .numberOver{        color:#8C2806;        font-size:14px;        width:280px;        background-color:#FFF;        text-align:center;        float:left;        display: block;        margin-left:10px;        }.main{    width:95%;    margin-left:auto;    margin-right:auto;    }    .left_indent{        padding-left:20px;        }    .red{        color:#F00;        }      </style> </head> <body> <div class="body"><img src="ad-01.jpg" width="524" height="190" border="0" alt="廣告圖片" id="Rotator"> <div class="bg"> <div class="number" id="fig_1" onclick="show(1);">1</div> <div class="number" id="fig_2" onclick="show(2);">2</div> <div class="number" id="fig_3" onclick="show(3);">3</div> <div class="number" id="fig_4" onclick="show(4);">4</div>  </div> </div> </body> <script type="text/javascript"> // JavaScript Document//定義全域變數var title=new Array();title[0]="1.店慶第一波 限時搶購 一日三瘋!";title[1]="2.十年店慶均價場 39/99/169專場!";title[2]="3.全場69折封頂 享噹噹的超值低價!";title[3]="4.店慶钜獻 海量圖書69折封頂";var NowFrame = 1;   //最先顯示第一張圖片var MaxFrame = 4;   //一共五張圖片function show(d1) {    if(Number(d1)){        clearTimeout(theTimer);  //當觸動按扭時,清除計時器        NowFrame=d1;                //設當前顯示圖片        }    for(var i=1;i<(MaxFrame+1);i++){        if(i==NowFrame){                        document.getElementById("Rotator").src ="ad-0"+i+".jpg";   //顯示當前圖片            document.getElementById("fig_"+i).innerHTML=title[i-1];       //顯示當前圖片對應的標題            document.getElementById("fig_"+i).className="numberOver";    //設定當前標題的CSS樣式         }         else{         document.getElementById("fig_"+i).innerHTML=i;         document.getElementById("fig_"+i).className="number";         }    }    if(NowFrame == MaxFrame){   //設定下一個顯示的圖片        NowFrame = 1;        }    else{        NowFrame++;        }}var theTimer=setInterval(‘show()‘, 3000);   //設定定時器,顯示下一張圖片window.onload=show;    //頁面載入時運行函數show()    </script></html>

 

JavaScript圖片輪播,舉一反三

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.