JQuery轮播图

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		
		<style type="text/css">
			*{margin: 0;padding: 0;}
			.main{
				width: 1000px;
				margin: 0 auto;
				margin-top: 50px;
				position: relative;
				overflow: hidden;
			}
		
			
			#left{
				position: absolute;
				top: 45%;
				left: 20px;
				transition: all 0.5s;
				opacity: 0.7;
				cursor: pointer;
			}
			#right{
				position: absolute;
				top: 45%;
				right: 20px;
				transition: all 0.5s;
				opacity: 0.7;
				cursor: pointer;
			}
			#left:hover {
				transform: scale(1.3);
				opacity: 1;
			}
			#right:hover{
				transform: scale(1.3);
				opacity: 1;
			}
			.yuan{
				position: absolute;
				bottom: 15px;
				left: 50%;
				transform: translate(-50%,0);
			}
			.yuan span{
				display: block;
				width: 15px;
				height: 15px;
				background: #fff;
				border-radius: 50%;
				float: left;
				margin-left: 10px;
			}
			.yuan span.focus{
				background: hotpink;
			}
			.imgWrap{
				width: 1000000px;
				
			}
			.imgWrap li{
				float: left;
				list-style: none;
			}
		</style>
	</head>
	<body>
		
		<div class="main">
			<ul class="imgWrap" style="margin-left: 0;">
				<li><img src="./images/1.jpg" ></li>
				<li><img src="./images/2.jpg" ></li>
				<li><img src="./images/3.jpg" ></li>
				<li><img src="./images/4.jpg" ></li>
				<li><img src="./images/5.jpg" ></li>
				<li><img src="./images/6.jpg" ></li>
			
			</ul>
			<p id="left"><img src="images/l.png" ></p>
			<p id="right"> <img src="images/r.png" ></p>
			
			<div class="yuan">
				
			</div>
		</div>
		
		<script src="jquery.min.js"></script>
		<script type="text/javascript">
			let n=0;
			let liList=$(".imgWrap li")
			let ul=$(".imgWrap")
			function changImg(){
				ul.animate({
					marginLeft:-(n*1000)
				})
				spanList.removeClass("focus")
				spanList.eq(n).addClass("focus")
			}
			$("#right").click(function(){
				if(n<liList.length-1){
					n++
				}else{
					n=0
				}
				changImg()
			})
			$("#left").click(function(){
				if(n===0){
					n=liList.length-1
				}else{
					n--
				}
				changImg()
			})
			let yuan=$(".yuan")
			for(var i=0;i<liList.length;i++){
				var span=document.createElement("span")
				yuan.append(span)
			}
			let spanList=$(".yuan span")
			spanList.eq(0).addClass("focus")
			spanList.click(function(){
				n=$(this).index()
				changImg()
			})

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值