用html画一个竖向轮播图加横向轮播图,我只需要插入我的图片
时间: 2024-05-07 19:03:18 浏览: 210
好的,以下是一个简单的竖向轮播图加横向轮播图的HTML代码,你只需要将其中的图片链接替换成你自己的图片链接即可:
```html
<!DOCTYPE html>
<html>
<head>
<title>轮播图示例</title>
<style>
/* 竖向轮播图样式 */
.vertical-slider {
height: 400px;
overflow: hidden;
position: relative;
}
.vertical-slider img {
height: 400px;
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 1s ease-in-out;
}
.vertical-slider img.active {
opacity: 1;
transition: opacity 1s ease-in-out;
}
/* 横向轮播图样式 */
.horizontal-slider {
width: 100%;
height: 200px;
display: flex;
overflow-x: scroll;
overflow-y: hidden;
scroll-behavior: smooth;
}
.horizontal-slider img {
height: 200px;
flex-shrink: 0;
margin-right: 10px;
}
</style>
</head>
<body>
<!-- 竖向轮播图 -->
<div class="vertical-slider">
<img src="图片链接1" class="active">
<img src="图片链接2">
<img src="图片链接3">
</div>
<!-- 横向轮播图 -->
<div class="horizontal-slider">
<img src="图片链接4">
<img src="图片链接5">
<img src="图片链接6">
<img src="图片链接7">
<img src="图片链接8">
</div>
<script>
// 竖向轮播图JS代码
let verticalSlider = document.querySelector('.vertical-slider');
let verticalImages = verticalSlider.querySelectorAll('img');
let currentVerticalIndex = 0;
setInterval(() => {
verticalImages[currentVerticalIndex].classList.remove('active');
currentVerticalIndex = (currentVerticalIndex + 1) % verticalImages.length;
verticalImages[currentVerticalIndex].classList.add('active');
}, 3000);
// 横向轮播图JS代码
let horizontalSlider = document.querySelector('.horizontal-slider');
let horizontalImages = horizontalSlider.querySelectorAll('img');
let currentHorizontalIndex = 0;
setInterval(() => {
horizontalImages[currentHorizontalIndex].scrollIntoView({behavior: 'smooth'});
currentHorizontalIndex = (currentHorizontalIndex + 1) % horizontalImages.length;
}, 3000);
</script>
</body>
</html>
```
这个代码包含了两个轮播图,一个是竖向的轮播图,一个是横向的轮播图。你可以根据自己的需要修改轮播图的高度、宽度、图片链接和轮播间隔等参数。
阅读全文