JS原生之-----带导航的轮播图jq版

21 篇文章 0 订阅
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>轮播图-欣欣博客</title>
		<style>
			* {
				padding: 0;
				margin: 0;
			}
			
			#banner {
				width: 600px;
				height: 200px;
				overflow: hidden;
				position: relative;
				margin: auto;
			}
			
			.banner-ul {
				width: 3600px;
				height: 200px;
				list-style: none;
				position: absolute;
				left: 0;
				top: 0;
			}
			
			.banner-ul-li {
				float: left;
				width: 600px;
				height: 200px;
				text-align: center;
				line-height: 200px;
			}
			
			.banner-nav {
				width: 125px;
				height: 15px;
				position: absolute;
				right: 10px;
				bottom: 10px;
			}
			
			.banner-nav li {
				list-style: none;
				float: left;
				margin-right: 10px;
				width: 15px;
				height: 15px;
				border-radius: 50%;
				text-align: center;
				background: black;
				color: #fff;
				font-size: 12px;
			}
		</style>
		<script src="jquery-1.11.0.js"></script>
		<script>
			$(function() {
				var $banner = $("#banner");
				var currentIndex = 0;
				var autoTabImg = setInterval(tabImg, 1000);

				function tabImg() {
					if(currentIndex > 5) {
						$("#banner :first").css("left", "0");
						currentIndex = 1;
					}
					tabNav();
					$("#banner :first").animate({
						left: -600 * currentIndex
					}, function() {
						currentIndex++;
					});
				}

				function tabNav() {
					$(".banner-nav li").each(function() {
							$(this).css("background", "");
						})
						//导航切换
					$(".banner-nav li").eq(currentIndex == 5 ? 0 : currentIndex).css("background", "gray");
				};

				$banner.mouseenter(function() {
					clearInterval(autoTabImg);
				});

				$banner.mouseleave(function() {
					autoTabImg = setInterval(tabImg, 1000);
				});
				$(".banner-nav li").each(function() {
					$(this).click(function() {
						currentIndex = $(this).index();
						tabImg();
						console.log();
					})
				})

			})
		</script>
	</head>

	<body>
		<div id="banner">
			<ul class="banner-ul">
				<li class="banner-ul-li" style="background:red;">学习</li>
				<li class="banner-ul-li" style="background:yellow;">交流</li>
				<li class="banner-ul-li" style="background:blue;">评论</li>
				<li class="banner-ul-li" style="background:green;">点赞</li>
				<li class="banner-ul-li" style="background:orange;">进步</li>
				<li class="banner-ul-li" style="background:red;">学习</li>
			</ul>
			<ul class="banner-nav">
				<li>1</li>
				<li>2</li>
				<li>3</li>
				<li>4</li>
				<li>5</li>
			</ul>

		</div>
	</body>

</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值