jquery 圖片自動切換

來源:互聯網
上載者:User

[html]     [html] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  <html xmlns="http://www.w3.org/1999/xhtml">  <head>  <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  <title>JQUERY實現圖片自動切換</title>  <style>  body{margin:0px; padding:0px; font-family:Arial}  ul{list-style:none;margin:0px;padding:0px}  .click_out{margin-left:5px; float:left; text-align:center; height:16px; line-height:16px; width:16px; background:#333; color:#FFF; font-weight:bold; font-size:12px; cursor:pointer;_display:inline-block; }  .click_over{margin-left:5px; float:left;text-align:center; height:16px; line-height:16px; width:16px; background:#820000; color:#FFF; font-weight:bold; font-size:12px; cursor:pointer; _display:inline-block; }  </style>  <script language="javascript" src="../Script/jquery-1.4.4.min.js"></script>  </head>  <body>    <div style="height:230px; width:980px; background:#EBEBEB; position:relative" id="flash_outer">       <div style=" position:absolute; left:0px; top:0px; width:980px; height:230px; overflow:hidden" id="flash_pic">          <div style="width:980px; height:250px; background:url(flash_pic/1.jpg)"></div>          <div style="width:980px; height:250px; background:url(flash_pic/2.jpg)"></div>          <div style="width:980px; height:250px; background:url(flash_pic/3.jpg)"></div>          <div style="width:980px; height:250px; background:url(flash_pic/4.jpg)"></div>       </div>       <ul style="position:absolute; right:0px; bottom:0px; height:16px" id="flash_num">         <li class="click_over">1</li>         <li class="click_out">2</li>         <li class="click_out">3</li>         <li class="click_out">4</li>       </ul>    </div>  <script language="javascript">  $(document).ready(function()  {     var len=$("#flash_num>li").length;     var index=1;     var int;     function showSys(num)  //圖片切換函數     {      $("#flash_num>li").removeClass().addClass("click_out").eq(num).toggleClass("click_out").addClass("click_over");      $("#flash_pic>div").fadeOut().eq(num).fadeIn();     }     function ziDong()  //自動切換     {      if(index==len)      {       index=0;      }      showSys(index);      index=index+1;     }     int=setInterval(ziDong,3000);     $("#flash_num>li").click(function() //點擊切換     {      var index_num=$("#flash_num>li").index(this);      showSys(index_num);      index=index_num+1;  //改變全域變數的值,以便滑鼠移開的時候能夠銜接上      //$(".click_out").removeClass("click_over").eq(index).addClass("click_over");      //$(".click_out").eq(index).removeClass().addClass("click_over");         //alert(index);     });     $("#flash_outer").mouseover(function()  //移動到上面時停止自動切換         {          clearInterval(int);         });     $("#flash_outer").mouseout(function()  //移開時繼續自動切換         {          int=setInterval(ziDong,3000);         });  });  </script>  </body>  </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.