码迷,mamicode.com
首页 > 其他好文 > 详细

模仿轮播图效果

时间:2014-08-14 16:32:38      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:style   http   os   io   ar   2014   art   cti   

<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>手写轮播图效果</title>
<style>
#imgsDiv{position: relative;height: 400px;}
.picDiv{
position: absolute;
top:0;
left:0;
width:100%;
height: 400px;
background-position: center center;
background-repeat: no-repeat;
z-index:0;
}
#dotLists{
position: relative;
margin:-30px auto 0;
text-align:center;
height: 20px;
z-index: 20;
}
.dot{
display: inline-block;
width: 12px;
height: 12px;
margin:0 8px;
border-radius: 50%;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
-o-border-radius: 50%;
background: #ccc;
cursor: pointer;
}
.hover{
background: #FF1515;
}
</style>
<script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div id="imgsDiv">
<div class="picDiv" style="background-image:url(https://i.alipayobjects.com/i/ecmng/jpg/201407/31kKIcRiQ3.jpg);"></div>
<div class="picDiv" style="background-image:url(https://i.alipayobjects.com/i/ecmng/jpg/201406/2pMuCMfPWf_src.jpg);"></div>
<div class="picDiv" style="background-image:url(https://i.alipayobjects.com/i/ecmng/jpg/201406/2pMuBhXfEr_src.jpg);"></div>
<div class="picDiv" style="background-image:url(https://i.alipayobjects.com/i/ecmng/jpg/201406/2pMuC9bBef_src.jpg);"></div>
</div>
<p id="dotLists">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</p>
<script>
//轮播
var Rotation=function($div1,$div2){
this.$list1=$div1.children();
this.$list2=$div2.children();
this.timeOut=null;
//初始化
this._start();
}
Rotation.prototype={
_init:function(){
this.$list1.hide()
.eq(0).show().css("z-index","1").addClass("show")
this.$list2.eq(0).addClass(‘hover‘);
},
_start:function(){
var _this=this;
_this._init();
_this._startTimeOut();
_this._addClickEvent(_this.$list2);
_this.$list1.hover(function(){
_this._stopTimeOut();
},function(){
_this._startTimeOut();
});
},
_addClickEvent:function($div){
var _this=this;
$div.on("click",function(){
_this._stopTimeOut();
_this.$list1.stop(true,true);
_this._doNext($(this).index());
});
},
_doNext:function(index){
var _this=this;
var num=_this.$list2.siblings(".hover").index();
_this.$list2.eq(index).addClass("hover")
.siblings().removeClass("hover");
if(num!=index){
_this.$list1.eq(index).show().addClass("show").end()
.eq(num).removeClass("show").fadeOut(900,function(){
_this.$list1.eq(index).css("z-index","1").end()
.eq(num).css("z-index","0");
});
}
},
_startTimeOut:function(){
var _this=this;
var indexNum=_this.$list2.siblings(".hover").index();
timeOut=setInterval(function(){
indexNum++;
_this._doNext(indexNum%(_this.$list1.length));
},3000);
},
_stopTimeOut:function(){
clearInterval(timeOut);
}
}


$(function(){
//调用轮播
new Rotation($("#imgsDiv"),$("#dotLists"));
});
</script>
</body>
</html>

模仿轮播图效果,布布扣,bubuko.com

模仿轮播图效果

标签:style   http   os   io   ar   2014   art   cti   

原文地址:http://www.cnblogs.com/goodbeypeterpan/p/3912628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!