jQuery图片轮播代码实现

Css实现:  

 

#hero img{
	width: 100%;
	height: 100%;
}
#hero div{
	position: absolute;
	top: 0px; 
	left: 0px; 
	display: none; 
	z-index: 5; 
	opacity: 0; 
	width: 645px; 
	height: 590px;
}
#hero-pager {
	z-index: 2;
	text-align: center;
	margin: 20px 0;
}
#hero-pager a {
	margin: 0 4px;
	display: inline-block;
	width: 14px;
	height: 14px;
	border-radius: 14px;
	text-indent: -3000em;
	background-color: #D0D0D0;
	vertical-align: middle;
}
#hero-pager a.activeSlide {
	width: 21px;
	height: 21px;
	border-radius: 21px;
	background-color: #85C637;
}

 

Html实现:  

<div id="hero" style="display: table-cell;position: relative; width: 645px; height: 590px;">
			<div>
				<img src="https://www.yapp.us/images/home/hero/derek.jpg" />
			</div>
			<div>
				<img src="https://www.yapp.us/images/home/hero/julie.jpg" />
			</div>
			<div>
				<img src="https://www.yapp.us/images/home/hero/dan.jpg" />
			</div>
			<div>
				<img src="https://www.yapp.us/images/home/hero/wojtek.jpg" />
			</div>
			<div>
				<img src="https://www.yapp.us/images/home/hero/caitlin.jpg" />
			</div>
		</div>
		<div class="hero-controls">
		  <div id="hero-pager">
		  <a href="#" class="activeSlide">*</a><a href="#" class="">*</a><a href="#">*</a><a href="#" class="">*</a><a href="#" class="">*</a></div>
		</div>

 

Js实现:

var curIndex = 0;
setInterval(function(){
	curIndex = (curIndex >= $("#hero-pager a").size() ? 0 : curIndex);
	$("#hero-pager a").removeClass("activeSlide").eq(curIndex).addClass("activeSlide");
	$("#hero div").css({"display":"none","z-index":"5","opacity":"0"}).eq(curIndex).css({"display":"block","z-index":"6","opacity":"1"});
	
	curIndex++;
}, 3000);

$("#hero-pager a").hover(function(){
	$("#hero-pager a").removeClass("activeSlide");
	$(this).addClass("activeSlide");
	curIndex = $("#hero-pager a").index(this);
	$("#hero div").css({"display":"none","z-index":"5","opacity":"0"}).eq(curIndex).css({"display":"block","z-index":"6","opacity":"1"});
}).click(function(){
	$("#hero div").css({"display":"none","z-index":"5","opacity":"0"}).eq(curIndex).css({"display":"block","z-index":"6","opacity":"1"});
	return false;
});

  

Demo:http://each.sinaapp.com/vtec/home.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值