jQuery輪播圖功能制作方法詳解
本文實例講述了jQuery輪播圖功能制作方法。分享給大家供大家參考,具體如下:
在寫輪播圖之前我們先看看這個輪播圖完成后的樣式是怎樣的
素材圖片 :
代碼
HTML代碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="css/index.css" rel="external nofollow" > </head> <body> <div class="banner"> <ul class="banner-img"> <li class="show"><img src="img/1.jpg" alt="" class="src"></li> <li><img src="img/2.jpg" alt="" class="src"></li> <li><img src="img/3.jpg" alt="" class="src"></li> <li><img src="img/4.jpg" alt="" class="src"></li> <li><img src="img/5.jpg" alt="" class="src"></li> </ul> <div class="banner-body"> <ul class="banner-body-img" id="bannerUl"> <li class="active"><img src="img/1.jpg" alt="" class="src"></li> <li><img src="img/2.jpg" alt="" class="src"></li> <li><img src="img/3.jpg" alt="" class="src"></li> <li><img src="img/4.jpg" alt="" class="src"></li> <li><img src="img/5.jpg" alt="" class="src"></li> </ul> <div class="banner-text"> <div class="text-active"> <p>山河</p><p>一個人</p><p>我眺望遠方</p> </div> <div> <p>夕陽</p><p>平靜的湖水</p><p>美麗不可方物</p> </div> <div> <p>沙漠</p><p>廣袤</p><p>一往無前</p> </div> <div> <p>溫泉</p><p>游客</p><p>魂牽夢繞</p> </div> <div> <p>大海</p><p>一棵樹</p><p>紫氣東來</p> </div> </div> </div> </div> <script src="../js/jquery-2.1.1.js"></script> <script src="js/index.js"></script> </body> </html>
CSS代碼
*{ padding: 0; margin: 0; } body{ background: #000; } .banner{ margin-left: 15%; width: 70%; position: relative; } .src{ max-width: 100%; } .banner-img{ list-style: none; } .banner-body{ width: 100%; position: absolute; bottom: 0; background: #fff; } .banner-img>li{ display: none; } .banner-img>.show{ display: block; animation: opcaty 2s; } @keyframes opcaty { from{ opacity: 0.2; } to { opacity: 1; } } .banner-body-img{ margin: 5px; max-width: 60%; list-style: none; } .banner-body-img>li{ display: inline-block; max-width: 18%; } .banner-body-img>.active{ border-bottom: 2px solid #000; animation: left 2s; } @keyframes left { from{ width : 0; } to{ width: 100% } } .banner-text{ width: 25%; position: absolute; bottom: 0; left: 70%; background: #493e56; color: #fff; } .banner-text>div{ overflow:auto; width: 100%; margin: 10px; display: none; } .banner-text>.text-active{ display: block; } .banner-text>div>p{ margin: 10px 0px; }
JS代碼
// 構(gòu)建索引值 var currIndex = 0; // 初始化點擊事件 initClick(); function initClick() { $(".banner-img li").hover(function () { $(".banner-body").stop().slideUp(); clearInterval(timer); },function () { timer = setInterval("banner()",3000); $(".banner-body").stop().slideDown(); }) $('#bannerUl li').click(function(){ $(this).addClass("active"); $(this).siblings().removeClass("active"); $(".banner-img li").eq($(this).index()).addClass("show"); $(".banner-img li").eq($(this).index()).siblings().removeClass("show"); $(".banner-text div").eq($(this).index()).addClass("text-active"); $(".banner-text div").eq($(this).index()).siblings().removeClass("text-active"); currIndex = $(this).index(); clearInterval(timer); timer = setInterval("banner()",3000); }); } //構(gòu)建定時器 var timer = setInterval("banner()",3000); function banner() { if (currIndex > 3) { currIndex = 0; } else { currIndex ++; } $(".banner-img li").eq(currIndex).addClass("show"); $(".banner-img li").eq(currIndex).siblings().removeClass("show"); $("#bannerUl li").eq(currIndex).addClass("active"); $("#bannerUl li").eq(currIndex).siblings().removeClass("active"); $(".banner-text div").eq(currIndex).addClass("text-active"); $(".banner-text div").eq(currIndex).siblings().removeClass("text-active"); }
如上。
感興趣的朋友可以使用在線HTML/CSS/JavaScript前端代碼調(diào)試運行工具:http://tools.jb51.net/code/WebCodeRun測試上述代碼運行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計有所幫助。
相關(guān)文章
用戶管理的設(shè)計_jquery的ajax實現(xiàn)二級聯(lián)動效果
下面小編就為大家?guī)硪黄脩艄芾淼脑O(shè)計_jquery的ajax實現(xiàn)二級聯(lián)動效果。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-07-07jQuery實現(xiàn)注冊會員時密碼強度提示信息功能示例
這篇文章主要介紹了jQuery實現(xiàn)注冊會員時密碼強度提示信息功能,涉及jQuery事件響應(yīng)及字符串的遍歷、運算與判斷等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09