帮我写一个轮播图的html页面
时间: 2024-06-06 07:11:41 浏览: 90
当然,我很乐意为您提供帮助。以下是一个简单的轮播图HTML页面的模板:
<!DOCTYPE html>
<html>
<head>
<title>轮播图页面</title>
<style>
/* 样式表 */
</style>
</head>
<body>
<div class="slideshow-container">
<div class="mySlides fade">
<img src="slide1.jpg" style="width:100%">
<div class="text">标题 1</div>
</div>
<div class="mySlides fade">
<img src="slide2.jpg" style="width:100%">
<div class="text">标题 2</div>
</div>
<div class="mySlides fade">
<img src="slide3.jpg" style="width:100%">
<div class="text">标题 3</div>
</div>
<a class="prev" onclick="plusSlides(-1)">❮</a>
<a class="next" onclick="plusSlides(1)">❯</a>
</div>
<br>
<div style="text-align:center">
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
</script>
</body>
</html>
希望这可以帮助您快速创建一个简单的轮播图页面。
阅读全文