jquery實(shí)現(xiàn)焦點(diǎn)輪播效果
更新時(shí)間:2017年02月23日 10:19:54 作者:ljz1490614196
本文主要介紹了jquery實(shí)現(xiàn)焦點(diǎn)輪播效果的示例代碼,具有很好的參考價(jià)值,下面跟著小編一起來看下吧
HTML代碼
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href="./css/lunbo.css" rel="external nofollow" > </head> <body> <div id="banner"> <ul class="img-ul"></ul> <ol class="index-ol"></ol> <div class="slide"> <span class="prev"><</span> <span class="next">></span> </div> </div> <script src="./js/jquery-1.11.3.js"></script> <script src="./js/lunbo.js"></script> </body> </html>
css代碼
div {
width: 670px;
height: 240px;
position: relative;
overflow: hidden;
}
div > ul,
div ol {
list-style: none;
position: absolute;
margin: 0;
padding: 0;
}
div > ul.img-ul,
div ol.img-ul {
width: 3350px;
height: 240px;
z-index: 100;
}
div > ul.img-ul > li,
div ol.img-ul > li {
float: left;
width: 670px;
height: 240px;
}
div > ul.index-ol,
div ol.index-ol {
width: 205px;
bottom: 10px;
left: 217px;
z-index: 1000;
}
div > ul.index-ol > li,
div ol.index-ol > li {
float: left;
cursor: pointer;
margin-left: 20px;
background: #000;
color: #fff;
border-radius: 50%;
height: 20px;
width: 20px;
text-align: center;
line-height: 20px;
}
div > ul.index-ol > li.active,
div ol.index-ol > li.active {
background: red;
}
div > div.slide {
z-index: 500;
position: absolute;
width: 670px;
height: 240px;
left: 0;
top: 0;
}
div > div.slide > span {
cursor: pointer;
position: absolute;
top: 100px;
width: 30px;
height: 60px;
line-height: 60px;
text-align: center;
font-size: 20px;
color: #fff;
background: rgba(0, 0, 0, 0.2);
}
div > div.slide > span:nth-child(1) {
left: 0;
}
div > div.slide > span:nth-child(2) {
right: 0;
}
JavaScript代碼
var arr=[
{"img":"./images/banner_01.jpg"},
{"img":"./images/banner_02.jpg"},
{"img":"./images/banner_03.jpg"},
{"img":"./images/banner_04.jpg"},
{"img":"./images/banner_05.jpg"},
];
var lunbo={
can:0, //判斷
ul_li:"",//圖片列表
ol_li:"",//數(shù)字列表
width:"",//一個(gè)li的寬度
interval:"",//定時(shí)器
init:function(){
console.log(this);
this.view();
this.view_index();
$("ol.index-ol").children("li:eq(0)").addClass("active");
this.width=$("ul.img-ul>li").width(); //670
this.slide(); //這是左右箭頭
this.animation_index();//這是下標(biāo)
this.play(); //這是自動(dòng)輪播
this.mouse(); //這是鼠標(biāo)滑入/滑出
},
mouse:function(){
var _this=this;
$("#banner").on({
mouseenter:function(){
_this.stop()
},
mouseleave:function(){
_this.play();
}
})
},
play:function(){
this.interval=setInterval(function(){
var active_index= parseInt($("ol.index-ol>li.active").attr("data-index"));//得到當(dāng)前激活向下標(biāo)
$("ol.index-ol>li").removeClass("active");
$(this).addClass("active");
this.animation(1);
(active_index==4)&&(active_index=-1);
$("ol.index-ol>li:eq("+(active_index+1)+")").addClass("active")
}.bind(this),3000);
},
stop:function(){
clearInterval(this.interval)
this.interval=null;
},
animation_index:function(){//更新下標(biāo)
var _this=this;
$("ol.index-ol>li").mouseenter(function(){//點(diǎn)擊下標(biāo)
var active_index= $("ol.index-ol>li.active").attr("data-index");//得到當(dāng)前激活向下標(biāo)
var index=$(this).attr("data-index");//得到當(dāng)前下標(biāo);
if(active_index==index){return;};
$("ol.index-ol>li").removeClass("active");
$(this).addClass("active");
var end=index-active_index;
_this.animation(-end)
})
},
slide:function(){//點(diǎn)擊左右箭頭
var _this=this;
$("div.slide>span").click(function(){
if(_this.can){return;};
var active_index= parseInt($("ol.index-ol>li.active").attr("data-index"));//得到當(dāng)前激活向下標(biāo)
$("ol.index-ol>li").removeClass("active");
if(this.className=="prev"){
_this.animation(1);
(active_index==1)&&(active_index=5);
$("ol.index-ol>li:eq("+(active_index-1)+")").addClass("active")
}else{
_this.animation(-1);
(active_index==4)&&(active_index=-1);
$("ol.index-ol>li:eq("+(active_index+1)+")").addClass("active")
}
})
},
view:function(){//更新圖片
for(var i=0;i<arr.length;i++){
this.ul_li+="<li data-index="+i+"><img src="+arr[i].img+"></li>"
}
$("ul.img-ul").html(this.ul_li);
this.ul_li="";
},
view_index:function(){//更新數(shù)字
for(var i=0;i<arr.length;i++){
this.ol_li+="<li data-index="+i+">"+(i+1)+"</li>"
}
$("ol.index-ol").html(this.ol_li);
},
animation:function(n){//做動(dòng)畫
this.can=1;
if(n<0){
arr=arr.splice(arr.length+n,-n).concat(arr);
this.view();
$("ul.img-ul").css({"left":n*this.width+"px"});
$("ul.img-ul").animate({"left":"0px"},1000,function(){
this.can=0;
}.bind(this));
}else{
$("ul.img-ul").animate({"left":-n*this.width+"px"},1000,function(){
arr=arr.concat(arr.splice(0,n));
this.view();
$("ul.img-ul").css({"left":0+"px"});
this.can=0;
}.bind(this));
}
}
};
lunbo.init();
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
您可能感興趣的文章:
- jQuery焦點(diǎn)圖輪播效果實(shí)現(xiàn)方法
- jQuery焦點(diǎn)圖輪播插件KinSlideshow用法分析
- 基于jquery實(shí)現(xiàn)輪播焦點(diǎn)圖插件
- 輕量級(jí)jQuery插件slideBox實(shí)現(xiàn)帶底欄輪播(焦點(diǎn)圖)代碼
- 基于JQuery實(shí)現(xiàn)圖片輪播效果(焦點(diǎn)圖)
- jQuery插件實(shí)現(xiàn)帶圓點(diǎn)的焦點(diǎn)圖片輪播切換
- jQuery右側(cè)選項(xiàng)卡焦點(diǎn)圖片輪播特效代碼分享
- jQuery焦點(diǎn)圖輪播特效代碼分享(3款)
- 基于JQuery的實(shí)現(xiàn)圖片輪播效果(焦點(diǎn)圖)
相關(guān)文章
JavaScript jQuery 中定義數(shù)組與操作及jquery數(shù)組操作
這篇文章主要介紹了JavaScript jQuery 中定義數(shù)組與操作及jquery數(shù)組操作的相關(guān)資料,需要的朋友可以參考下2015-12-12
jQuery實(shí)現(xiàn)鼠標(biāo)經(jīng)過時(shí)出現(xiàn)隱藏層文字鏈接的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)鼠標(biāo)經(jīng)過時(shí)出現(xiàn)隱藏層文字鏈接的方法,涉及jQuery鼠標(biāo)hover事件的響應(yīng)及頁面元素的動(dòng)態(tài)處理技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10
jQuery實(shí)現(xiàn)獲取form表單內(nèi)容及綁定數(shù)據(jù)到form表單操作分析
這篇文章主要介紹了jQuery實(shí)現(xiàn)獲取form表單內(nèi)容及綁定數(shù)據(jù)到form表單操作,結(jié)合jQuery封裝插件操作分析了jQuery針對(duì)form表單的serializeJson數(shù)據(jù)獲取及setForm數(shù)據(jù)綁定相關(guān)操作技巧,需要的朋友可以參考下2018-07-07
jquery實(shí)現(xiàn)鼠標(biāo)滑過顯示二級(jí)下拉菜單效果
這篇文章主要介紹了jquery實(shí)現(xiàn)鼠標(biāo)滑過顯示二級(jí)下拉菜單效果,通過jquery操作鼠標(biāo)事件及頁面樣式動(dòng)態(tài)變換實(shí)現(xiàn)該功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-08-08
jquery實(shí)現(xiàn)具有嵌套功能的選項(xiàng)卡
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)具有嵌套功能的選項(xiàng)卡的相關(guān)資料,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-02-02

