fadein和fadeout 轮播

记一下代码,防止遗忘:

<!-- 有bug!!!-->

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>demo</title>
	<script type="text/javascript" src="jquery-1.12.1.min.js"></script>
	<script>
		$(document).ready(function(){
			var len=$(".picBox li").length;
			var startRollOne;
			var previous_index;
			var current_index; //将要显示的图片索引
			$(".picBox li").fadeOut(0).eq(0).fadeIn(0); //隐藏所有,并显示第一个
			 previous_index = 0; //正在显示的图片索引

			$(".num li").mouseover(function () {
				 current_index = $(".num li").index(this);
				showImg(current_index);
			});


			$(".box").hover(function () {
				clearInterval(startRollOne);
			}, function () {
				startRollOne = setInterval(function () {
					current_index =previous_index+1;
					if(current_index == len){
						current_index = 0;
					}
					showImg(current_index);
				},2000);
			}).trigger("mouseleave");

			function  showImg(num){
				$(".picBox li").eq(previous_index).fadeOut(600).end().eq(num).fadeIn(600);//这里使用siblings()有bug,使用end()可以,为什么
				$(".num li").removeClass("on").eq(num).addClass("on");
				previous_index=num;
			}
		});
	</script>
	<style>
		.box{
			width: 200px;
			height: 260px;
			margin: 160px auto;
			position: relative;
		}
		.box p{
			text-align: center;
		}
		.picBox{
			margin: 0px;
			padding: 0px;
			list-style: none;
			width: 1500px;
			position: absolute;
		}
		.picBox:hover{
			cursor: pointer;
		}
		.picBox li{
			position: absolute;
			display: none;
			top:0px;
			left:0px;
		}
		.dispoint{
			display: none;
		}
		.picBox img{
			width: 200px;
			height: 240px;
		}
		.num {
			list-style: none;
			position: absolute;
			bottom: 1px;
			right: 10px;
		}
		.num li{
			text-align: center;
			width: 15px;
			height:15px;
			background-color: white;
			opacity: 1;
			line-height: 18px;
			float: left;
			border: red solid 1px;
			margin-left: 2px;
			font-size: 15px;
		}
		.num li.on{
			text-align: center;
			width: 20px;
			height:20px;
			background-color: red;
			opacity: 1;
			font-size: 18px;
			line-height: 20px;
			float: left;
			border: red solid 1px;
			margin-left: 2px;
		}
	</style>
</head>
<body>
<div class="box">
	<p> 图片轮播</p>
	<ul class="picBox">
		<li><img src="a.jpg" /></li>
		<li><img src="b.jpg" /></li>
		<li><img src="c.jpg" /></li>
		<li><img src="d.jpg" /></li>
		<li><img src="e.jpg" /></li>
	</ul>
	<ul class="num">
		<li class="on">1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
		<li>5</li>
	</ul>

</div>
</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值