浅谈jQuery实现轮播

<!DOCTYPE html>
<html>
	<head>
		<style type="text/css">
			#frame{
				width:700px;
				height:300px;
				position:relative;
			}
			#img2,#img3{
				display:none;
			}
			.box{
				position:absolute;
				width:50px;
				height:50px;
				line-height:50px;
				text-align:center;
				color:white;
				font-family:Microsoft-Yahei;
				background:grey;
			}
			#move1{
				bottom:0;
				right:100px;
			}
			#move2{
				bottom:0;
				right:50px;
			}
			#move3{
				bottom:0;
				right:0;
			}
		</style>
		<script src="js/jquery-1.8.2.min.js"></script>
		<script>
			$(document).ready(function() {
				n = 1;
				interval = setInterval(
					function(){
						$("img").hide();
						$("#img"+n).show();
						$(".box").css("background","grey");
						$("#move"+n).css("background","red");
						n = n % 3 + 1;
					}
					, 
					2000
				);
				$(".box").bind("click",function() {
					clearInterval(interval);
					n = $(this).attr("id").slice(4);
					interval = setInterval(
						function(){
							$("img").hide();
							$("#img"+n).show();
							$(".box").css("background","grey");
							$("#move"+n).css("background","red");
							n = n % 3 + 1;
						}
						, 
						2000
					);
				});
			});
		</script>
	</head>
	<body>
		<div id="frame">
			<div id="photos">
				<img id="img1" src="images/background1.png">
				<img id="img2" src="images/background2.png">
				<img id="img3" src="images/background3.png">
			</div>
			<div class="box" id="move1">1</div>
			<div class="box" id="move2">2</div>
			<div class="box" id="move3">3</div>
		</div>
	</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值