jquery實現簡單的banner輪播效果【執行個體】,jquerybanner

來源:互聯網
上載者:User

jquery實現簡單的banner輪播效果【執行個體】,jquerybanner

朋友給我看了一個輪播效果,把js下載一看,丫丫的一個這麼簡單的效果,這麼的就能寫個幾百行的,嚴重影響瀏覽器載入速度嘛,以為人家寬頻流量不要錢玩的哦。。無奈之下給他寫了個簡單的,把所有代碼放上去都沒有超過70行,還有圓角的那個CSS,不是每個瀏覽器都是圓角的,不過不影響美觀,嘻嘻。

<html xmlns="http://www.w3.org/1999/xhtml" ><head>  <title>無標題頁</title>  <script src="js/jquery-2.1.4.js" type="text/javascript"></script>  <style type="text/css">    .clear{overflow:hidden; clear:both; width:0px; height:0px; }    .imgbox{width:640px; margin:0 auto; text-align:center; }    ul{padding:0px; margin:0px;}    ul li{float:left; list-style:none; }    ul li.select{display:block;}    .imgnum span{border-radius:10px; font:normal normal bold 12px/15px 微軟雅黑; color:#FFF; margin-left:5px; padding:3px 6px 3px 6px; background-color:#F90; cursor:pointer;}    .imgnum span.onselect{background-color:#F00;}    .imgnum{text-align:center; float:right; margin:-30px 30px; position:relative;}  </style></head><body>  <div class="imgbox">      <ul id="banner_img">        <li><img src="images/banner1.jpg"/></li>        <li><img src="images/banner2.jpg"/></li>        <li><img src="images/banner3.jpg"/></li>        <li><img src="images/banner4.jpg"/></li>        <li><img src="images/banner5.jpg"/></li>      </ul>  <div class="clear"></div>  <div class="imgnum">    <span class="onselect">1</span>    <span>2</span>    <span>3</span>    <span>4</span>    <span>5</span>  </div></div><script type="text/javascript">     var time = "";     var index = 1;     $(function () {       showimg(index);       //滑鼠移入移出       $(".imgnum span").hover(function () {        clearTimeout(time);        var icon=$(this).text();        $(".imgnum span").removeClass("onselect").eq(icon-1).addClass("onselect");        $("#banner_img li").hide().stop(true,true).eq(icon-1).fadeIn("slow");       }, function () {        index=$(this).text()> 4 ? 1 :parseInt($(this).text())+1;        time = setTimeout("showimg(" + index + ")", 3000);       });     });      function showimg(num) {       index = num;       $(".imgnum span").removeClass("onselect").eq(index-1).addClass("onselect");       $("#banner_img li").hide().stop(true,true).eq(index-1).fadeIn("slow");       index = index + 1 > 5 ? 1 : index + 1;       time = setTimeout("showimg(" + index + ")", 3000);     }  </script></body></html>

注意要引用 Jquery 檔案,圖片我就不放上來了,自己替換掉,注意圖片長寬。

如下:

以上這篇jquery實現簡單的banner輪播效果【執行個體】就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援幫客之家。

聯繫我們

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