做一个简易旅游首页,要有十种网页特效,包含轮播图,下拉列表的级联,简易留言板,简易计算器,动态时钟,其他你自行添加
时间: 2023-08-13 21:06:25 浏览: 96
好的,我可以给您提供一个简易旅游首页的代码,包含以下特效:
1. 轮播图
2. 下拉列表级联
3. 留言板
4. 计算器
5. 动态时钟
6. 图片放大缩小
7. 鼠标悬停动画
8. 按钮点击效果
9. 弹出框
10. 滚动动画
以下是代码示例:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>旅游首页</title>
<style>
/* 定义轮播图样式 */
.slider {
width: 800px;
height: 400px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
.slider img {
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: opacity 1s ease-in-out;
width: 100%;
height: 100%;
object-fit: cover;
}
.slider img.active {
opacity: 1;
}
/* 定义下拉列表级联样式 */
select {
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
}
.sub-select {
display: none;
}
/* 定义留言板样式 */
.form {
width: 400px;
margin: 0 auto;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.form label {
display: block;
margin-bottom: 5px;
}
.form input[type="text"], .form textarea {
width: 100%;
padding: 5px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.form input[type="submit"] {
padding: 5px 10px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
/* 定义计算器样式 */
.calculator {
width: 300px;
margin: 0 auto;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.calculator label {
display: block;
margin-bottom: 5px;
}
.calculator input[type="text"] {
width: 100%;
padding: 5px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}
.calculator input[type="submit"] {
padding: 5px 10px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}
/* 定义动态时钟样式 */
.clock {
width: 200px;
height: 200px;
margin: 0 auto;
position: relative;
border-radius: 50%;
}
.clock .hour-hand, .clock .minute-hand, .clock .second-hand {
position: absolute;
top: 0;
left: 50%;
width: 5px;
height: 80px;
margin-left: -2.5px;
background-color: #000;
transform-origin: bottom center;
border-radius: 5px 5px 0 0;
transition: all 0.1s linear;
}
.clock .hour-hand {
height: 60px;
background-color: #ccc;
}
.clock .minute-hand {
background-color: #666;
}
.clock .second-hand {
height: 70px;
background-color: #f00;
}
/* 定义图片放大缩小样式 */
.image {
width: 200px;
height: 200px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.image img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: all 0.2s ease-in-out;
}
.image:hover img {
transform: scale(1.2);
}
/* 定义鼠标悬停动画样式 */
.hover-animation {
width: 200px;
height: 200px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
.hover-animation:before {
content: "";
display: block;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
position: absolute;
top: 0;
left: 0;
opacity: 0;
transition: all 0.2s ease-in-out;
}
.hover-animation:hover:before {
opacity: 1;
}
.hover-animation img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: all 0.2s ease-in-out;
}
.hover-animation:hover img {
transform: scale(1.2);
}
/* 定义按钮点击效果样式 */
.button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: all 0.2s ease-in-out;
}
.button:hover {
background-color: #0069d9;
}
/* 定义弹出框样式 */
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.5);
z-index: 9999;
justify-content: center;
align-items: center;
}
.modal .content {
width: 500px;
height: 300px;
background-color: #fff;
padding: 20px;
border-radius: 5px;
text-align: center;
position: relative;
}
.modal .close {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
}
/* 定义滚动动画样式 */
.scroll-animation {
opacity: 0;
transform: translateY(50px);
transition: all 0.2s ease-in-out;
}
.scroll-animation.show {
opacity: 1;
transform: translateY(0);
}
</style>
</head>
<body>
<div class="slider">
<img src="https://picsum.photos/800/400?random=1" class="active">
<img src="https://picsum.photos/800/400?random=2">
<img src="https://picsum.photos/800/400?random=3">
<img src="https://picsum.photos/800/400?random=4">
<img src="https://picsum.photos/800/400?random=5">
</div>
<br>
<div>
<select id="province-select">
<option value="">请选择省份</option>
<option value="北京">北京</option>
<option value="上海">上海</option>
<option value="广东">广东</option>
</select>
<select id="city-select" class="sub-select">
<option value="">请选择城市</option>
</select>
<select id="district-select" class="sub-select">
<option value="">请选择区县</option>
</select>
</div>
<br>
<div class="form">
<h3>留言板</h3>
<form action="" method="post">
<label for="name">姓名:</label>
<input type="text" id="name" name="name">
<label for="email">邮箱:</label>
<input type="text" id="email" name="email">
<label for="message">留言:</label>
<textarea id="message" name="message"></textarea>
<input type="submit" value="提交">
</form>
</div>
<br>
<div class="calculator">
<h3>计算器</h3>
<form action="">
<label for="num1">数字1:</label>
<input type="text" id="num1" name="num1">
<label for="num2">数字2:</label>
<input type="text" id="num2" name="num2">
<input type="submit" value="计算">
</form>
<p id="result"></p>
</div>
<br>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
</div>
<br>
<div class="image">
<img src="https://picsum.photos/200/200?random=1">
</div>
<br>
<div class="hover-animation">
<img src="https://picsum.photos/200/200?random=2">
</div>
<br>
<button class="button">点击试试</button>
<br>
<div class="modal">
<div class="content">
<h3>弹出框</h3>
<p>这是一个弹出框</p>
<div class="close">X</div>
</div>
</div>
<br>
<div class="scroll-animation">这是一个滚动动画</div>
<script>
//定义轮播图
let slider = document.querySelector('.slider');
let images = document.querySelectorAll('.slider img');
let index = 0;
function changeImage() {
images[index].classList.remove('active');
index = (index + 1) % images.length;
images[index].classList.add('active');
}
setInterval(changeImage, 3000);
//定义下拉列表级联
let provinceSelect = document.querySelector('#province-select');
let citySelect = document.querySelector('#city-select');
let districtSelect = document.querySelector('#district-select');
provinceSelect.addEventListener('change', function() {
//清空城市列表和区县列表
citySelect.innerHTML = '<option value="">请选择城市</option>';
districtSelect.innerHTML = '<option value="">请选择区县</option>';
//根据省份获取城市列表
if (this.value === '北京') {
citySelect.innerHTML += '<option value="北京市">北京市</option>';
} else if (this.value === '上海') {
citySelect.innerHTML += '<option value="上海市">上海市</option>';
} else if (this.value === '广东') {
citySelect.innerHTML += '<option value="广州市">广州市</option>';
citySelect.innerHTML += '<option value="深圳市">深圳市</option>';
}
//显示城市列表
citySelect.classList.remove('sub-select');
});
citySelect.addEventListener('change', function() {
//清空区县列表
districtSelect.innerHTML = '<option value="">请选择区县</option>';
//根据城市获取区县列表
if (this.value === '北京市') {
districtSelect.innerHTML += '<option value="东城区">东城区</option>';
districtSelect.innerHTML += '<option value="西城区">西城区</option>';
} else if (this.value === '上海市') {
districtSelect.innerHTML += '<option value="黄浦区">黄浦区</option>';
districtSelect.innerHTML += '<option value="徐汇区">徐汇区</option>';
} else if (this.value === '广州市') {
districtSelect.innerHTML += '<option value="天河区">天河区</option>';
districtSelect.innerHTML += '<option value="海珠区">海珠区</option>';
} else if (this.value === '深圳市') {
districtSelect.innerHTML += '<option value="福田区">福田区</option>';
districtSelect.innerHTML += '<option value="南山区">南山区</option>';
}
//显示区县列表
districtSelect.classList.remove('sub-select');
});
//定义留言板
let form = document.querySelector('.form');
let nameInput = document.querySelector('#name');
let emailInput = document.querySelector('#email');
let messageInput = document.querySelector('#message');
form.addEventListener('submit', function(e) {
e.preventDefault();
alert(`姓名:${nameInput.value}\n邮箱:${emailInput.value}\n留言:${messageInput.value}`);
this.reset();
});
//定义计算器
let num1Input = document.querySelector('#num1');
let num2Input = document.querySelector('#num2');
let resultP = document.querySelector('#result');
form = document.querySelector('.calculator');
form.addEventListener('submit', function(e) {
e.preventDefault();
let num1 = Number(num1Input.value);
let num2 = Number(num2Input.value);
resultP.innerText = `结果:${num1 + num2}`;
});
//定义动态时钟
let hourHand = document.querySelector('.hour-hand');
let minuteHand = document.querySelector('.minute-hand');
let secondHand = document.querySelector('.second-hand');
function updateClock() {
let date = new Date();
let hours = date.getHours() % 12;
let minutes = date.getMinutes();
let seconds = date.getSeconds();
hourHand.style.transform = `rotate(${hours / 12 * 360 + minutes / 60 * 30 - 90}deg)`;
minuteHand.style.transform = `rotate(${minutes / 60 * 360 + seconds / 60 * 6 - 90}deg)`;
secondHand.style.transform = `rotate(${seconds / 60 * 360 - 90}deg)`;
}
setInterval(updateClock, 1000);
//定义弹出框
let button = document.querySelector('.button');
let modal = document.querySelector('.modal');
let close = document.querySelector('.close');
button.addEventListener('click', function() {
modal.style.display = 'flex';
});
close.addEventListener('click', function() {
modal.style.display = 'none';
});
//定义滚动动画
let scrollAnimations = document.querySelectorAll('.scroll-animation');
window.addEventListener('scroll', function() {
scrollAnimations.forEach(function(animation) {
if (animation.offsetTop + animation.offsetHeight < window.pageYOffset + window.innerHeight) {
animation.classList.add('show');
}
});
});
</script>
</body>
</html>
```
阅读全文