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

淡入淡出轮播图

时间:2016-05-20 19:12:25      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>
<head>
<style type="text/css">

body{background:#57beb9;}
/* main */
#main{width:920px;height:430px;overflow:hidden;position:relative;margin:30px auto;}
#main .box{width:820px;height:430px;box-shadow:0px 0px 5px #ddd;margin:0px auto;overflow:hidden;position:relative;}
#main .box img{width:820px;height:430px;position:absolute;left:0px;top:0px;opacity:0;filter:alpha(opacity=0);}
#main .btnLeft{width:35px;height:57px;position:absolute;left:0px;top:185px;background:url(images/left_ar.png) no-repeat 0px 0px;}
#main .btnRight{width:35px;height:57px;position:absolute;right:0px;top:185px;background:url(images/right_ar.png) no-repeat 0px 0px;}
#main .page{width:132px;height:22px;position:absolute;bottom:15px;right:50px;}
#main .page a{display:inline-block;width:22px;height:22px;background:url(images/num_grey.png) no-repeat 0px 0px;margin:0px 11px;float:left;color:#FFF;text-decoration:none;text-align:center;}
#main .page a.active{background:url(images/num_red.png) no-repeat 0px 0px;}

</style>
</head>
<body>
<div id="main">
<a class="btnLeft" id="btnLeft" href="javascript:void(0);"></a>
<a class="btnRight" id="btnRight" href="javascript:void(0);"></a>
<div class="box">
<img style="opacity: 1;" src="images/intro1.jpg">
<img src="images/intro2.jpg" style="opacity: 0;">
<img src="images/intro3.jpg" style="opacity: 0;">
</div>
<div class="page">
<a class="active" href="javascript:void(0);">1</a>
<a href="javascript:void(0);" class="">2</a> <a href="javascript:void(0);" class="">3</a>
</div>
</div>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript">

$(function(){

var aPage = $(‘#main .page a‘);
var aImg = $(‘#main .box img‘);
var iSize = aImg.size();
var index = 0;
var t;
$(‘#btnLeft‘).click(function(){
index--;
if(index<0){
index=iSize-1
}
change(index)
})
$(‘#btnRight‘).click(function(){
index++;
if(index>iSize-1){
index=0
}
change(index)
})

aPage.click(function(){
index = $(this).index();
change(index)
});

function change(index){
aPage.removeClass(‘active‘);
aPage.eq(index).addClass(‘active‘);
aImg.stop();

aImg.eq(index).siblings().animate({
opacity:0
},1000)

aImg.eq(index).animate({
opacity:1
},1000)
}


function autoshow() {
index=index+1;
if(index<=iSize-1){
change(index);
}else{
index=0;
change(index);
}

}
int=setInterval(autoshow,3000);
function clearInt() {
$(‘#btnLeft,#btnRight,.page a‘).mouseover(function() {
clearInterval(int);
})

}
function setInt() {
$(‘#btnLeft,#btnRight,.page a‘).mouseout(function() {
int=setInterval(autoshow,3000);
})
}
clearInt();
setInt();
})

</script>
</body>
</html>

淡入淡出轮播图

标签:

原文地址:http://www.cnblogs.com/xiaotaiyang/p/5512819.html

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