HTML5七夕情人节表白网页制作【结婚倒计时】HTML+CSS+JavaScript html生日快乐祝福网页制作
warning:
这篇文章距离上次修改已过205天,其中的内容可能已经有所变动。
以下是一个简单的HTML5生日快乐祝页面示例,使用HTML、CSS和JavaScript制作。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>婚礼倒计时</title>
<style>
body {
margin: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background-color: #f7f7f7;
font-family: Arial, sans-serif;
}
.countdown {
text-align: center;
color: #333;
}
h1 {
font-size: 3em;
margin: 0.67em 0;
}
.timer {
font-size: 2em;
}
</style>
</head>
<body>
<div class="countdown">
<h1>婚礼快到来啦!</h1>
<div id="timer" class="timer"></div>
</div>
<script>
// 设置结婚的日期
const weddingDate = new Date('2023-08-08T20:00:00'); // 示例日期,请替换为你的结婚日期
function countdown() {
const now = new Date();
const distance = weddingDate - now;
if (distance < 0) {
clearInterval(intervalId);
document.getElementById('timer').innerText = '欢喜庆祝!';
return;
}
const days = Math.floor(distance / (1000 * 60 * 60 * 24));
const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById('timer').innerText = `${days} 天 ${hours} 小时 ${minutes} 分 ${seconds} 秒`;
}
countdown();
const intervalId = setInterval(countdown, 1000);
</script>
</body>
</html>
这段代码会在网页上显示一个倒计时,直至结婚的日期。你需要替换weddingDate
变量的值为你自己的结婚日期。这个简单的例子使用了JavaScript中的Date
对象来计算时间差异,并通过ID为timer
的元素显示剩余时间。
评论已关闭