jQuery輪播圖功能制作方法詳解
本文實(shí)例講述了jQuery輪播圖功能制作方法。分享給大家供大家參考,具體如下:
在寫(xiě)輪播圖之前我們先看看這個(gè)輪播圖完成后的樣式是怎樣的
素材圖片 :
代碼
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>一個(gè)人</p><p>我眺望遠(yuǎn)方</p> </div> <div> <p>夕陽(yáng)</p><p>平靜的湖水</p><p>美麗不可方物</p> </div> <div> <p>沙漠</p><p>廣袤</p><p>一往無(wú)前</p> </div> <div> <p>溫泉</p><p>游客</p><p>魂?duì)繅?mèng)繞</p> </div> <div> <p>大海</p><p>一棵樹(shù)</p><p>紫氣東來(lái)</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; // 初始化點(diǎn)擊事件 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)建定時(shí)器 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)試運(yùn)行工具:http://tools.jb51.net/code/WebCodeRun測(cè)試上述代碼運(yùn)行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見(jiàn)經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- 利用jquery寫(xiě)的左右輪播圖特效
- jquery 實(shí)現(xiàn)輪播圖詳解及實(shí)例代碼
- jQuery插件slides實(shí)現(xiàn)無(wú)縫輪播圖特效
- jQuery自適應(yīng)輪播圖插件Swiper用法示例
- jQuery實(shí)現(xiàn)輪播圖及其原理詳解
- 基于jQuery實(shí)現(xiàn)淡入淡出效果輪播圖
- jQuery按需加載輪播圖(web前端性能優(yōu)化)
- jquery實(shí)現(xiàn)的簡(jiǎn)單輪播圖功能【適合新手】
- 原生Javascript和jQuery做輪播圖簡(jiǎn)單例子
- jQuery實(shí)現(xiàn)簡(jiǎn)潔的輪播圖效果實(shí)例
相關(guān)文章
jquery文檔操作wrap()方法實(shí)例簡(jiǎn)述
這篇文章主要介紹了jquery文檔操作wrap()方法,以實(shí)例形式簡(jiǎn)單分析了wrap()方法用某個(gè)標(biāo)簽將某個(gè)元素包起來(lái)的使用技巧,需要的朋友可以參考下2015-01-01jQuery事件注冊(cè)的實(shí)現(xiàn)示范
jQuery為我們提供了方便的事件注冊(cè)機(jī)制,它的優(yōu)點(diǎn),操作簡(jiǎn)單,且不用擔(dān)心事件覆蓋等問(wèn)題。缺點(diǎn),普通的事件注冊(cè)不能做事件委托,且無(wú)法實(shí)現(xiàn)事件解綁,需要借助其他方法2022-07-07用戶管理的設(shè)計(jì)_jquery的ajax實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)效果
下面小編就為大家?guī)?lái)一篇用戶管理的設(shè)計(jì)_jquery的ajax實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)效果。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-07-07jQuery實(shí)現(xiàn)的圖片分組切換焦點(diǎn)圖插件
這篇文章主要介紹了jQuery實(shí)現(xiàn)的圖片分組切換焦點(diǎn)圖插件,效果非常棒,而且很實(shí)用,推薦給有需要的小伙伴。2015-01-01jQuery實(shí)現(xiàn)注冊(cè)會(huì)員時(shí)密碼強(qiáng)度提示信息功能示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)注冊(cè)會(huì)員時(shí)密碼強(qiáng)度提示信息功能,涉及jQuery事件響應(yīng)及字符串的遍歷、運(yùn)算與判斷等相關(guān)操作技巧,需要的朋友可以參考下2017-09-09