今天就跟大家聊聊有關(guān)使用jQuery怎么實現(xiàn)一個輪播圖功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

創(chuàng)新互聯(lián)建站專業(yè)為企業(yè)提供尖山網(wǎng)站建設、尖山做網(wǎng)站、尖山網(wǎng)站設計、尖山網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、尖山企業(yè)網(wǎng)站模板建站服務,十余年尖山做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。
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");
}看完上述內(nèi)容,你們對使用jQuery怎么實現(xiàn)一個輪播圖功能有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
網(wǎng)頁標題:使用jQuery怎么實現(xiàn)一個輪播圖功能
URL標題:http://www.chinadenli.net/article22/ishscc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設、網(wǎng)站內(nèi)鏈、靜態(tài)網(wǎng)站、服務器托管、商城網(wǎng)站、網(wǎng)站導航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)