jQuery實現(xiàn)帶進度條的輪播圖
更新時間:2020年09月13日 13:12:14 作者:暗鎖讀客
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)帶進度條的輪播圖,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jQuery實現(xiàn)帶進度條輪播圖的具體代碼,供大家參考,具體內(nèi)容如下
1.html模塊
<div class="banner"> <ul> <li style="background: url(img/bg1.jpg) center;"> <img src="img/con1.png" /> <div class="nav"></div> <div class="bar"> <p></p> </div> </li> <li style="background: url(img/bg2.jpg) center;"> <img src="img/con2.png" /> <div class="nav"></div> <div class="bar"> <p></p> </div> </li> <li style="background: url(img/bg3.jpg) center;"> <img src="img/con3.png" /> <div class="nav"></div> <div class="bar"> <p></p> </div> </li> </ul> </div>
2.css模塊
<style type="text/css">
*{
margin: 0;
padding: 0;
list-style: none;
}
.banner{
width: 100%;
height: 600px;
position: relative;
}
ul li{
width: 100%;
height: 600px;
position: absolute;
top: 0;
left: 0;
overflow:hidden;
}
ul li img{
width: 100%;
height: 600px;
position: absolute;
left: -100%;
}
.nav{
width: 100%;
height: 70px;
background: rgba(255,255,255,0.3);
position: absolute;
bottom: 0;
}
.bar{
width: 80%;
height: 3px;
background-color: #999;
position: absolute;
bottom: 0;
left: 10%;
}
.bar p{
width: 0px;
height: 3px;
background-color: green;
}
</style>
3.jQuery模塊
<script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var i=0;//定義當(dāng)前索引
imgChange();//初始化調(diào)用
//定時切換
setInterval("imgChange()",6000);
//圖片輪播的函數(shù)
function imgChange(){
//進度條完成后顯示下一張背景
$("ul li").eq(i).fadeIn(100).siblings().fadeOut(100);
//初始化文字圖片---設(shè)置到外部
$("ul li").eq(i).find("img").css("left","-100%");
//初始化進度條
$("ul li").eq(i).find("p").css("width","0px");
//設(shè)置文字圖片從左進入的動畫
$("ul li").eq(i).find("img").animate({"left":"0px"},500,function(){
//設(shè)置進度條動畫
$("ul li").eq(i).find("p").animate({"width":"100%"},5000,function(){
$("ul li").eq(i).find("img").animate({left:"100%"},400);
//改變當(dāng)前索引,當(dāng)索引為最后一個則設(shè)為0,否則就加一
if(i>=$("ul li").length-1){
i=0
}else{
i++;
}
})
})
}
</script>
4.方法二
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>帶進度條的輪播圖</title>
<script src="js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function () {
// 初始環(huán)境
var i=0,m;
tin(i);
// 定時器
m=setInterval(function () {
if (i>=2) {
i=0;
}else{
i++;
}
tin(i);
},5000);
})
// 動畫效果
var tin = function (i) {
$(".cont li").eq(i).find("img").css("left","-100%");
$(".bar span").css("width","0%");
$(".cont li").eq(i).fadeIn(100).siblings().fadeOut(100);
$(".cont li").eq(i).find("img").animate({left:"0%"},1000);
$(".bar span").animate({width:"100%"},4500,function () {
$(".cont li").eq(i).find("img").animate({left:"100%"},400);
});
}
</script>
<style type="text/css">
*{
margin: 0;
padding: 0;
list-style: none;
}
.box{
width: 100%;
height: 630px;
position: relative;
}
.cont{
width: 100%;
height: 630px;
position: relative;
overflow: hidden;
}
.cont li{
width: 100%;
height: 630px;
position: absolute;
top: 0;
left: 0;
}
.bar{
width: 70%;
height: 3px;
position: absolute;
bottom: 0px;
left: 15%;
background-color: white;
border-radius: 50px;
}
.bar span{
width: 0px;
display: block;
height: 80%;
background-color: green;
border-radius: 50px;
}
.cont li img{
width: 100%;
height: 630px;
position: absolute;
left: -100%;
top: 0;
}
.con1{
background: url(img/bg1.jpg) center;
}
.con2{
background: url(img/bg2.jpg) center;
}
.con3{
background: url(img/bg3.jpg) center;
}
.pav{
width: 100%;
height: 70px;
position: absolute;
bottom: 0px;
background-color: rgba(255,255,255,0.3);
}
</style>
</head>
<body>
<div id="main">
<div id="box" class="box">
<!--圖片-->
<ul class="cont">
<li class="con1"><img src="img/con1.png"/></li>
<li class="con2"><img src="img/con2.png"/></li>
<li class="con3"><img src="img/con3.png"/></li>
</ul>
<div class="pav"></div>
<!--進度條-->
<div class="bar">
<span></span>
</div>
</div>
</div>
</body>
</html>
精彩專題分享:jQuery圖片輪播 JavaScript圖片輪播 Bootstrap圖片輪播
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jquery form表單提交插件asp.net后臺中文解碼
對于jquery form表單提交插件jquery.form.js,在提交表單數(shù)據(jù)時,如果表單數(shù)據(jù)有中文,則被提交的數(shù)據(jù)是要經(jīng)過編碼的。2010-06-06
jQuery 1.9.1源碼分析系列(十)事件系統(tǒng)之主動觸發(fā)事件和模擬冒泡處理
這篇文章主要介紹了jQuery 1.9.1源碼分析系列(十)事件系統(tǒng)之主動觸發(fā)事件和模擬冒泡處理的相關(guān)資料,需要的朋友可以參考下2015-11-11
jQuery實現(xiàn)圣誕節(jié)禮物傳送(花式輪播)
本文主要對jQuery實現(xiàn)圣誕節(jié)禮物傳送的方法、思路進行詳細介紹,具有很好的參考價值,需要的朋友一起來看下吧2016-12-12

