本文實(shí)例為大家分享了jquery左右滑動(dòng)輪播圖的具體代碼,供大家參考,具體內(nèi)容如下

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<title>圖片輪播jq(左右切換)</title>
<style>
*{margin: 0;padding:0; }
ul{list-style: none;}
.banner{width: 600px;height: 300px;border: 2px solid #ccc;margin: 100px auto;position: relative;overflow: hidden;z-index: 1;}
.img{position: absolute;top: 0;left: 0;}
.des{position: absolute;bottom: 0;left: 0;z-index: -2;background: #ccc}
.des li{float: left;width: 600px;}
.img li{float: left;}
.num{position: absolute;bottom: 10px;width: 100%;text-align: center;font-size: 0;}
.num li{width: 10px;height: 10px;background:rgba(0,0,0,0.5);display: block;border-radius: 100%;display: inline-block;margin: 0 5px;cursor: pointer;}
.btn{display: none;}
.btn span{display: block;width: 50px;height: 100px;background: rgba(0,0,0,0.6);color: #fff;font-size: 40px;line-height: 100px;text-align: center;cursor:pointer;}
.btn .prev{position: absolute;left: 0;top: 50%;margin-top: -50px;}
.btn .next{position: absolute;right: 0;top: 50%;margin-top: -50px;}
.num .active{background-color: #fff;}
.hide{display: none;}
</style>
</head>
<body>
<div class="banner">
<ul class="img">
<li><a href="#"><img width="600" height="300" src="img/1.jpg" alt="第1張圖片"></a></li>
<li><a href="#"><img width="600" height="300" src="img/1.jpg" alt="第2張圖片"></a></li>
<li><a href="#"><img width="600" height="300" src="img/1.jpg" alt="第3張圖片"></a></li>
<li><a href="#"><img width="600" height="300" src="img/1.jpg" alt="第4張圖片"></a></li>
<li><a href="#"><img width="600" height="300" src="img/1.jpg" alt="第5張圖片"></a></li>
</ul>
<ul class="num"></ul>
<ul class="des">
<li>第一個(gè)</li>
<li>第二個(gè)</li>
<li>第三個(gè)</li>
<li>第四個(gè)</li>
<li>第五個(gè)</li>
<li>第一個(gè)</li>
</ul>
<div class="btn">
<span class="prev"><</span>
<span class="next">></span>
</div>
</div>
<script>
$(function(){
var i=0;
var timer=null;
for (var j = 0; j < $('.img li').length; j++) { //創(chuàng)建圓點(diǎn)
$('.num').append('<li></li>')
}
$('.num li').first().addClass('active'); //給第一個(gè)圓點(diǎn)添加樣式
var firstimg=$('.img li').first().clone(); //復(fù)制第一張圖片
$('.img').append(firstimg).width($('.img li').length*($('.img img').width()));
//第一張圖片放到最后一張圖片后,設(shè)置ul的寬度為圖片張數(shù)*圖片寬度
$('.des').width($('.img li').length*($('.img img').width()));
// 下一個(gè)按鈕
$('.next').click(function(){
i++;
if (i==$('.img li').length) {
i=1; //這里不是i=0
$('.img').css({left:0}); //保證無(wú)縫輪播,設(shè)置left值
};
$('.img').stop().animate({left:-i*600},300);
if (i==$('.img li').length-1) { //設(shè)置小圓點(diǎn)指示
$('.num li').eq(0).addClass('active').siblings().removeClass('active');
$('.des li').eq(0).removeClass('hide').siblings().addClass('hide');
}else{
$('.num li').eq(i).addClass('active').siblings().removeClass('active');
$('.des li').eq(i).removeClass('hide').siblings().addClass('hide');
}
})
// 上一個(gè)按鈕
$('.prev').click(function(){
i--;
if (i==-1) {
i=$('.img li').length-2;
$('.img').css({left:-($('.img li').length-1)*600});
}
$('.img').stop().animate({left:-i*600},300);
$('.num li').eq(i).addClass('active').siblings().removeClass('active');
$('.des li').eq(i).removeClass('hide').siblings().addClass('hide');
})
//設(shè)置按鈕的顯示和隱藏
$('.banner').hover(function(){
$('.btn').show();
},function(){
$('.btn').hide();
})
//鼠標(biāo)劃入圓點(diǎn)
$('.num li').mouseover(function(){
var _index=$(this).index();
$('.img').stop().animate({left:-_index*600},150);
$('.num li').eq(_index).addClass('active').siblings().removeClass('active');
$('.des li').eq(_index).removeClass('hide').siblings().addClass('hide');
})
//定時(shí)器自動(dòng)播放
timer=setInterval(function(){
i++;
if (i==$('.img li').length) {
i=1;
$('.img').css({left:0});
};
$('.img').stop().animate({left:-i*600},300);
if (i==$('.img li').length-1) {
$('.num li').eq(0).addClass('active').siblings().removeClass('active');
$('.des li').eq(0).removeClass('hide').siblings().addClass('hide');
}else{
$('.num li').eq(i).addClass('active').siblings().removeClass('active');
$('.des li').eq(i).removeClass('hide').siblings().addClass('hide');
}
},1000)
//鼠標(biāo)移入,暫停自動(dòng)播放,移出,開(kāi)始自動(dòng)播放
$('.banner').hover(function(){
clearInterval(timer);
},function(){
timer=setInterval(function(){
i++;
if (i==$('.img li').length) {
i=1;
$('.img').css({left:0});
};
$('.img').stop().animate({left:-i*600},300);
if (i==$('.img li').length-1) {
$('.num li').eq(0).addClass('active').siblings().removeClass('active');
$('.des li').eq(0).removeClass('hide').siblings().addClass('hide');
}else{
$('.num li').eq(i).addClass('active').siblings().removeClass('active');
$('.des li').eq(i).removeClass('hide').siblings().addClass('hide');
}
},1000)
})
})
</script>
</body>
</html>另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.chinadenli.net,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。
分享標(biāo)題:jquery實(shí)現(xiàn)左右滑動(dòng)式輪播圖-創(chuàng)新互聯(lián)
本文來(lái)源:http://www.chinadenli.net/article12/dccgdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動(dòng)態(tài)網(wǎng)站、ChatGPT、移動(dòng)網(wǎng)站建設(shè)、App設(shè)計(jì)、企業(yè)網(wǎng)站制作、手機(jī)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容