基于html+css+js的英雄联盟滚动图代码
时间: 2024-03-25 13:39:02 浏览: 66
以下是基于HTML、CSS和JavaScript的英雄联盟滚动图代码示例:
HTML代码:
```
<div class="slider">
<div class="slide"><img src="image1.jpg"></div>
<div class="slide"><img src="image2.jpg"></div>
<div class="slide"><img src="image3.jpg"></div>
</div>
```
CSS代码:
```
.slider {
width: 100%;
height: 400px;
overflow: hidden;
position: relative;
}
.slide {
width: 100%;
height: 400px;
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 1s ease-in-out;
}
.slide.active {
opacity: 1;
}
```
JavaScript代码:
```
const slides = document.querySelectorAll('.slide');
let currentSlide = 0;
const slideInterval = setInterval(nextSlide, 5000);
function nextSlide() {
slides[currentSlide].className = 'slide';
currentSlide = (currentSlide + 1) % slides.length;
slides[currentSlide].className = 'slide active';
}
```
以上代码实现了一个基本的英雄联盟滚动图功能,每隔5秒钟自动切换到下一张图片,同时也可以手动点击图片进行切换。
阅读全文