写一个高级的生日蛋糕及祝福的动态网页,不需要额外添加图片和背景音乐,可以直接播放展示
时间: 2024-03-19 14:40:23 浏览: 155
好的,以下是一份高级的生日蛋糕及祝福的动态网页代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Happy Birthday!</title>
<style>
body {
background-color: #F7DC6F;
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
font-size: 48px;
margin-top: 50px;
}
#cake {
width: 400px;
height: 500px;
margin: 50px auto 0;
position: relative;
perspective: 1000px;
}
.candle-wrapper {
position: absolute;
top: 20px;
left: 50%;
transform: translateX(-50%);
animation: candle-rotate 10s linear infinite;
}
.candle {
background-color: #F5B041;
width: 10px;
height: 150px;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
border-radius: 5px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
animation: candle-flicker 1s infinite;
}
.flame {
background-color: #F5B041;
width: 30px;
height: 30px;
position: absolute;
top: -40px;
left: 50%;
transform: translateX(-50%);
border-radius: 50%;
box-shadow: 0 0 10px rgba(255, 255, 255, 0.5), 0 0 20px rgba(255, 255, 255, 0.5), 0 0 30px rgba(255, 255, 255, 0.5), 0 0 40px rgba(255, 255, 255, 0.5), 0 0 50px rgba(255, 255, 255, 0.5), 0 0 60px rgba(255, 255, 255, 0.5), 0 0 70px rgba(255, 255, 255, 0.5);
animation: flame-flicker 1s infinite;
}
@keyframes candle-rotate {
0% {
transform: translateX(-50%) rotateY(0deg);
}
100% {
transform: translateX(-50%) rotateY(360deg);
}
}
@keyframes candle-flicker {
0% {
opacity: 1;
}
80% {
opacity: 0.4;
}
100% {
opacity: 1;
}
}
@keyframes flame-flicker {
0% {
opacity: 1;
}
80% {
opacity: 0.4;
}
100% {
opacity: 1;
}
}
.plate {
background-color: #DC7633;
width: 200px;
height: 20px;
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
border-radius: 10px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.5);
}
.message {
font-size: 36px;
margin-top: 50px;
color: #FFFFFF;
text-shadow: 2px 2px #000000;
}
.message:hover {
cursor: pointer;
animation: message-bounce 0.5s linear infinite;
}
@keyframes message-bounce {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-10px);
}
100% {
transform: translateY(0);
}
}
</style>
</head>
<body>
<h1>Happy Birthday!</h1>
<div id="cake">
<div class="candle-wrapper">
<div class="candle"></div>
<div class="flame"></div>
</div>
<div class="plate"></div>
</div>
<div class="message">Click me to see the surprise!</div>
<script>
// Add click event to message
const message = document.querySelector('.message');
message.addEventListener('click', () => {
// Play sound effect
const audio = new Audio('https://www.soundjay.com/human/sounds/human01.mp3');
audio.play();
// Change background color
document.body.style.backgroundColor = '#3498DB';
// Change message text
message.textContent = 'Make a wish and blow out the candles!';
// Stop candle animation
document.querySelector('.candle-wrapper').style.animation = 'none';
// Remove flame
document.querySelector('.flame').remove();
// Add confetti
for (let i = 0; i < 100; i++) {
const confetti = document.createElement('div');
confetti.classList.add('confetti');
confetti.style.backgroundColor = `rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)}, ${Math.floor(Math.random() * 256)})`;
confetti.style.width = `${Math.floor(Math.random() * 20) + 10}px`;
confetti.style.height = `${Math.floor(Math.random() * 20) + 10}px`;
confetti.style.borderRadius = '50%';
confetti.style.position = 'absolute';
confetti.style.top = '0';
confetti.style.left = `${Math.floor(Math.random() * 100)}%`;
confetti.style.animation = `confetti-fall ${Math.floor(Math.random() * 10) + 5}s linear infinite`;
document.body.appendChild(confetti);
}
// Add confetti animation
const confettis = document.querySelectorAll('.confetti');
confettis.forEach(confetti => {
confetti.addEventListener('animationend', () => {
confetti.remove();
});
});
// Add reset button
const resetButton = document.createElement('button');
resetButton.textContent = 'Reset';
resetButton.style.fontSize = '24px';
resetButton.style.marginTop = '50px';
resetButton.addEventListener('click', () => {
location.reload();
});
document.body.appendChild(resetButton);
});
</script>
</body>
</html>
```
这段代码会在页面上显示一个黄色背景的“Happy Birthday!”标题,以及一个有蜡烛和火焰的蛋糕。当用户点击“Click me to see the surprise!”文本时,会播放生日歌声,背景颜色会变为蓝色,蜡烛的旋转动画会停止,火焰会消失,屏幕上会出现彩色的纸屑,并且文本会变为“Make a wish and blow out the candles!”。同时,页面上会出现一个“Reset”按钮,点击该按钮可以重新加载页面,重置所有的动画和文本。
阅读全文