欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

轮播图

程序员文章站 2023-12-30 16:22:04
...

轮播图


roll.html

<!DOCTYPE html>
<html>
<head>
	<title></title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" 	href="roll.css">
</head>
<body>
	<div class="plate">
		<img src="images/img1.jpg" style="display:block" alt="">
		<img src="images/img2.jpg" alt="">
		<img src="images/img3.jpg" alt="">
		<img src="images/img4.jpg" alt="">
		<ul>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
		</ul>
	</div>
	<script src="roll.js"></script>
</body>
</html>

roll.css

*{
	margin: 0;
	padding: 0;
}
.plate{
	width: 520px;
	height: 280px;
	border: 2px solid red;
	margin: 20px auto;
	position: relative;
}
.plate img{
	float:left;
	overflow: hidden;
	position: absolute;
}
.plate ul{
	position: absolute;
	left: 230px;
	bottom: 20px;
}
.plate ul li{
	list-style: none;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	float: left;
	background-color: #999;
	margin-right: 8px;
}

roll.js

var plate = document.getElementsByClassName('plate')[0];
var list = plate.getElementsByTagName('li');
var imgs = plate.getElementsByTagName('img');
var count = 0;
setInterval(function(){
	count++;
	count = (count == 4? 0 : count);
	for(var i =0, len = list.length; i < len; i++){
		imgs[i].style.display = 'none';
		list[i].style.background = '#999';
	}
	imgs[count].style.display = 'block';
	list[count].style.background = 'red';
}, 1000);

上一篇:

下一篇: