jquery实现图片切换

记得先前用js实现了图片的切换,但是显示效果显示的很生硬,使用jQuery这种生硬得到了很好的缓解。但是由于技术问题,我写的效果虽然得到了一定的改善,可还是没有达到理想的效果。下面便是菜鸟代码,有很多不足有待改善,希望各位大神多多指导。


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>show</title>
		<meta name="author" content="Administrator" />
		<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
		<!-- Date: 2014-09-04 -->
		<style type="text/css">
			body {margin:0;padding:0;}img{border:none;}
			.banner{margin:0 auto;width:1002px;height:520px;background:#123555;position: relative;}
			.banner span{width:1002px;height: 520px;}
			.banner span img{width:1002px;height: 520px;}
			.hide{display: none;}
			.left,.right{width:64px;height:64px;top:208px;display:none;cursor:pointer;position:absolute;}
			.left{left:5px;}
			.right{right: 5px;}
			.explain{width:100%;height:40px;top:480px;text-align:center;background:#000000;position:absolute; }
			.explain ul{margin:0;padding:0;}
			.explain ul li{width:24px;height:40px;list-style:none;cursor:pointer;display:inline-block;background:url(images/triggers.png) no-repeat 6px 14px;}
			.explain .bannerNow{background:url(images/triggers_cur.png)  no-repeat 6px 14px;}
		</style>
		<script type="text/javascript">
$(document).ready(function(){
	//隐藏或者显示箭头
	$(".banner").mousemove(function(){
		$(".left,.right").css("display","block");
	});
	$(".banner").mouseout(function(){
		$(".left,.right").css("display","none");
	});
	//自动循环条件,hover()事件,mousemov和mouseout方法的结合
	var canLoop=true;
	$(".banner").hover(function(){
		canLoop=false;	
	},function(){
		canLoop = true;
	});
	var imgs=$(".banner span");
	var imgsIndex=0;
	//自动循环
	var loop=setInterval(plays, 5000);
	function plays(){
		if(canLoop){//判断条件
			imgsIndex=++imgsIndex;//imgsIndex++是错误的。
			if(imgsIndex>imgs.length-1){
				imgsIndex=0;
			}
			changeImg(imgsIndex);
		}}
	$(".left").click(function(){
		imgsIndex=--imgsIndex;
		if(imgsIndex<0){
			imgsIndex=imgs.length-1;
		}
		changeImg(imgsIndex);
	});
	$(".right").click(function(){
		imgsIndex=++imgsIndex;
		if(imgsIndex>imgs.length-1){
			imgsIndex=0;
		}
		changeImg(imgsIndex);
	});
	$('.explain ul li').click(function() {
		imgsIndex = $('.explain ul li').index($(this));
		changeImg(imgsIndex);
	});
});
function changeImg(index){
	//stop(),停止动画.animate(css,time).
	$(".banner span").hide().stop().animate({"filter":"alpha(opacity=0),","opacity":"0"},2000).eq(index).show().animate({"filter":"alpha(opacity=1),","opacity":"1"},2000);
	$(".explain ul li").eq(index).addClass("bannerNow").siblings().removeClass("bannerNow");  
}
		</script>
	</head>
	<body>
		<div class="banner">
			<span><a href="#"><img src="images/1.jpg"></a></span>
			<span class="hide"><a href="#"><img src="images/2.jpg"></a></span>
			<span class="hide"><a href="#"><img src="images/3.jpg"></a></span>
			<span class="hide"><a href="#"><img src="images/4.jpg"></a></span>
			<span class="hide"><a href="#"><img src="images/5.jpg"></a></span>
			<div class="left"><img src="images/left.png"></div>
			<div class="right"><img src="images/right.png"></div>
			<div class="explain">
				<ul>
					<li class="bannerNow"></li>
					<li></li>
					<li></li>
					<li></li>
					<li></li>
				</ul>
			</div>
		</div>
	</body>
</html>

源文件源代码免费下载地址:http://download.csdn.net/detail/u014703834/7862627

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值