如何在网页中,在网页顶部做一个导航,在网页中部放一个大图,网页下部外联js做一个无缝轮播,在网页右边缘做一个方形置顶按钮和方形咨询按钮的完整代码
时间: 2024-02-29 17:51:51 浏览: 88
完整代码如下所示:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>网页布局</title>
<style>
nav {
height: 50px;
background-color: #333;
color: #fff;
display: flex;
justify-content: space-between;
align-items: center;
}
nav ul {
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
nav li {
margin-right: 20px;
}
nav a {
color: #fff;
text-decoration: none;
}
.banner {
width: 100%;
height: 500px;
}
.banner img {
width: 100%;
height: 100%;
object-fit: cover;
}
.slider {
width: 100%;
height: 300px;
overflow: hidden;
}
.slider ul {
width: 300%;
height: 100%;
display: flex;
transition: transform 1s ease-in-out;
}
.slider li {
width: 33.33%;
}
.slider img {
width: 100%;
height: 100%;
object-fit: cover;
}
.fixed-buttons {
position: fixed;
right: 20px;
bottom: 20px;
display: flex;
flex-direction: column;
}
.fixed-buttons a {
display: block;
width: 50px;
height: 50px;
background-color: #ccc;
margin-bottom: 10px;
text-align: center;
line-height: 50px;
color: #fff;
text-decoration: none;
}
.fixed-buttons a:hover {
background-color: #666;
}
</style>
</head>
<body>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">产品介绍</a></li>
<li><a href="#">关于我们</a></li>
<li><a href="#">联系我们</a></li>
</ul>
<div>登录</div>
</nav>
<div class="banner">
<img src="https://picsum.photos/1200/500" alt="banner图片">
</div>
<div class="slider">
<ul>
<li><img src="https://picsum.photos/800/300" alt="轮播图1"></li>
<li><img src="https://picsum.photos/800/300" alt="轮播图2"></li>
<li><img src="https://picsum.photos/800/300" alt="轮播图3"></li>
</ul>
</div>
<div style="height: 2000px;"></div>
<div class="fixed-buttons">
<a href="#top" class="btn-top">置顶</a>
<a href="#" class="btn-consult">咨询</a>
</div>
<script>
const slider = document.querySelector('.slider');
let currentIndex = 1;
setInterval(() => {
slider.querySelector('ul').style.transform = `translateX(-${currentIndex * 33.33}%)`;
currentIndex++;
if (currentIndex >= 3) {
currentIndex = 0;
}
}, 3000);
</script>
</body>
</html>
```
注意,为了方便演示,我使用了一些随机占位图片。您可以替换成您自己的图片。
阅读全文