起初我看到别的博主发了一个这样的图
于是,我给chatgpt提出要求:
我想写一个html网页,上面是一个圆圆的时钟,下面写倒计时,距离新年还有多少天,多少小时,多少分钟,时钟有时针分针秒针,而且能够实时转动
第一步:新建一个新年时钟倒计时.html,里面填充内容如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Year Countdown</title>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
}
</style>
</head>
<body>
<div id="clock" class="clock"></div>
<div id="countdown"></div>
<script>
function updateClock() {
const clock = document.getElementById("clock");
const currentTime = new Date();
const seconds = currentTime.getSeconds();
const minutes = currentTime.getMinutes();
const hours = currentTime.getHours();
const secondsAngle = (seconds / 60) * 360;
const minutesAngle = ((minutes * 60 + seconds) / 3600) * 360;
const hoursAngle = ((hours * 3600 + minutes * 60 + seconds) / 43200) * 360;
clock.style.transform = `rotate(${secondsAngle}deg)`;
clock.innerHTML = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
setTimeout(updateClock, 1000);
}
function updateCountdown() {
const countdown = document.getElementById("countdown");
const now = new Date();
const newYear = new Date(now.getFullYear() + 1, 0, 1);
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
countdown.innerHTML = `Time remaining until New Year: ${days} days, ${hours} hours, ${minutes} minutes`;
setTimeout(updateCountdown, 1000);
}
updateClock();
updateCountdown();
</script>
</body>
</html>
第二步:点击调试开始运行![](https://i-blog.csdnimg.cn/blog_migrate/bcd2609299a472dc593f394f9ce6762a.png)
运行成果如图
不会做动图,凑合看。
总之就是一秒转一点,我说gpt烙铁,你别把我笑死。(无奈扶额)
重新调教了n次chatgpt,屡次调节效果如图
1.0版本
分针时针秒针该转不该转的都在转
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年时钟倒计时</title>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
position: relative;
animation: rotate 60s infinite linear;
}
.hour-hand, .minute-hand, .second-hand {
position: absolute;
background-color: black;
transform-origin: bottom center;
}
.hour-hand {
width: 4px;
height: 75px;
top: 50%;
left: 50%;
margin: -75px -2px 0;
animation: rotate 43200s infinite linear;
}
.minute-hand {
width: 2px;
height: 95px;
top: 50%;
left: 50%;
margin: -95px -1px 0;
animation: rotate 3600s infinite linear;
}
.second-hand {
width: 1px;
height: 105px;
top: 50%;
left: 50%;
margin: -105px;
animation: rotate 60s infinite linear;
}
@keyframes rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
</div>
<div id="countdown"></div>
<script>
function updateCountdown() {
const countdown = document.getElementById("countdown");
const now = new Date();
const newYear = new Date(2024, 1, 10); // 设置新年日期为2024年2月10日
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
countdown.innerHTML = `距离新年还有 ${days} 天, ${hours} 小时, ${minutes} 分钟, ${seconds} 秒`;
setTimeout(updateCountdown, 1000);
}
updateCountdown();
</script>
</body>
</html>
2.0版本
好家伙,这回直接负数了。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年时钟倒计时</title>
</head>
<body>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
<div class="hour-mark hour-mark1"></div>
<div class="hour-mark hour-mark2"></div>
<div class="hour-mark hour-mark3"></div>
<div class="hour-mark hour-mark4"></div>
<div class="hour-mark hour-mark5"></div>
<div class="hour-mark hour-mark6"></div>
<div class="hour-mark hour-mark7"></div>
<div class="hour-mark hour-mark8"></div>
<div class="hour-mark hour-mark9"></div>
<div class="hour-mark hour-mark10"></div>
<div class="hour-mark hour-mark11"></div>
<div class="hour-mark hour-mark12"></div>
</div>
<div id="countdown"></div>
<script>
function updateClock() {
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
const secondHand = document.querySelector(".second-hand");
const minuteHand = document.querySelector(".minute-hand");
const hourHand = document.querySelector(".hour-hand");
const secondHandRotation = seconds * 6;
const minuteHandRotation = (minutes * 6) + (seconds / 10);
const hourHandRotation = (hours * 30) + (minutes / 2);
secondHand.style.transform = `rotate(${secondHandRotation}deg)`;
minuteHand.style.transform = `rotate(${minuteHandRotation}deg)`;
hourHand.style.transform = `rotate(${hourHandRotation}deg)`;
setTimeout(updateClock, 1000);
}
function updateCountdown() {
const countdown = document.getElementById("countdown");
const now = new Date();
const newYear = new Date(2023, 1, 10, 0, 0, 0); // 新年时间为2023年2月10日00:00
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
countdown.innerHTML = `距离2023年2月10日新年还有 ${days} 天, ${hours} 小时, ${minutes} 分钟, ${seconds} 秒`;
setTimeout(updateCountdown, 1000);
}
updateClock();
updateCountdown();
</script>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
position: relative;
}
.hour-hand, .minute-hand, .second-hand {
position: absolute;
background-color: black;
}
.hour-hand {
width: 4px;
height: 75px;
top: calc(50% - 52px);
left: calc(50% - 2px);
transform-origin: bottom center;
}
.minute-hand {
width: 2px;
height: 95px;
top: calc(50% - 72px);
left: calc(50% - 1px);
transform-origin: bottom center;
}
.second-hand {
width: 1px;
height: 105px;
top: calc(50% - 92px);
left: calc(50% - 0.5px);
transform-origin: bottom center;
}
.hour-mark {
position: absolute;
width: 2px;
height: 15px;
background-color: black;
top: calc(50% - 97px);
left: calc(50% - 1px);
transform-origin: bottom center;
transform: translateX(-50%) rotateZ(-30deg);
}
.hour-mark:nth-child(even) {
transform: translateX(-50%) rotateZ(-60deg);
}
.hour-mark1 { transform: translateX(-50%) rotateZ(-30deg); }
.hour-mark2 { transform: translateX(-50%) rotateZ(-60deg); }
.hour-mark3 { transform: translateX(-50%) rotateZ(-90deg); }
.hour-mark4 { transform: translateX(-50%) rotateZ(-120deg); }
.hour-mark5 { transform: translateX(-50%) rotateZ(-150deg); }
.hour-mark6 { transform: translateX(-50%) rotateZ(-180deg); }
.hour-mark7 { transform: translateX(-50%) rotateZ(-210deg); }
.hour-mark8 { transform: translateX(-50%) rotateZ(-240deg); }
.hour-mark9 { transform: translateX(-50%) rotateZ(-270deg); }
.hour-mark10 { transform: translateX(-50%) rotateZ(-300deg); }
.hour-mark11 { transform: translateX(-50%) rotateZ(-330deg); }
.hour-mark12 { transform: translateX(-50%) rotateZ(0deg); }
</style>
</body>
</html>
再来
3.0版本
还是在一起转动,并且我的倒计时文字还被吃掉了,再来!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年时钟倒计时</title>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
position: relative;
animation: rotate 60s infinite linear;
}
.hour-hand, .minute-hand, .second-hand {
position: absolute;
background-color: black;
transform-origin: bottom center;
}
.hour-hand {
width: 4px;
height: 75px;
top: 50%;
left: 50%;
margin: -75px -2px 0;
transform: rotate(0deg); /* 设置初始旋转角度为 0 度 */
animation: rotate 43200s infinite linear;
}
.minute-hand {
width: 2px;
height: 95px;
top: 50%;
left: 50%;
margin: -95px -1px 0;
transform: rotate(0deg); /* 设置初始旋转角度为 0 度 */
animation: rotate 3600s infinite linear;
}
.second-hand {
width: 1px;
height: 105px;
top: 50%;
left: 50%;
margin: -105px;
transform: rotate(0deg); /* 设置初始旋转角度为 0 度 */
animation: rotate 60s infinite linear;
}
@keyframes rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
</div>
<!-- 倒计时显示部分的代码省略 -->
<script>
function updateClock() {
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
const secondHand = document.querySelector(".second-hand");
const minuteHand = document.querySelector(".minute-hand");
const hourHand = document.querySelector(".hour-hand");
// 根据当前时间设置初始旋转角度
secondHand.style.transform = `rotate(${seconds * 6}deg)`; // 每秒钟旋转 6 度
minuteHand.style.transform = `rotate(${minutes * 6}deg)`; // 每分钟旋转 6 度
hourHand.style.transform = `rotate(${(hours % 12) * 30}deg)`; // 每小时旋转 30 度
setTimeout(updateClock, 1000);
}
updateClock();
</script>
</body>
</html>
4.0版本
真的有点气笑了,倒计时怎么搞出404天了,要不直接404not found算了。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年时钟倒计时</title>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
position: relative;
animation: rotate 60s infinite linear;
}
.hour-hand, .minute-hand, .second-hand {
position: absolute;
background-color: black;
transform-origin: bottom center;
}
.hour-hand {
width: 4px;
height: 75px;
top: 50%;
left: 50%;
margin: -75px -2px 0;
transform: rotate(0deg);
animation: rotate 43200s infinite linear;
}
.minute-hand {
width: 2px;
height: 95px;
top: 50%;
left: 50%;
margin: -95px -1px 0;
transform: rotate(0deg);
animation: rotate 3600s infinite linear;
}
.second-hand {
width: 1px;
height: 105px;
top: 50%;
left: 50%;
margin: -105px;
transform: rotate(0deg);
animation: rotate 60s infinite linear;
}
@keyframes rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
</div>
<div id="countdown"></div>
<script>
function updateCountdown() {
const countdown = document.getElementById("countdown");
const now = new Date();
const newYear = new Date(now.getFullYear() + 1, 1, 10); // 下一年的2月10日作为新年时间
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
countdown.innerHTML = `距离新年还有 ${days} 天, ${hours} 小时, ${minutes} 分钟, ${seconds} 秒`;
setTimeout(updateCountdown, 1000);
}
updateCountdown();
</script>
</body>
</html>
5.0版本
这回时针分针不转了,倒计时又没了,而且秒表依然在外面漂泊。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年时钟倒计时</title>
</head>
<body>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
</div>
<script>
function updateClock() {
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
const secondHand = document.querySelector(".second-hand");
const minuteHand = document.querySelector(".minute-hand");
const hourHand = document.querySelector(".hour-hand");
// 计算时针、分针和秒针的旋转角度
const secondHandRotation = seconds * 6; // 每秒钟旋转 6 度
const minuteHandRotation = (minutes * 6) + (seconds / 10); // 每分钟旋转 6 度,每秒钟旋转 0.1 度
const hourHandRotation = (hours * 30) + (minutes / 2); // 每小时旋转 30 度,每分钟旋转 0.5 度
// 应用旋转角度
secondHand.style.transform = `rotate(${secondHandRotation}deg)`;
minuteHand.style.transform = `rotate(${minuteHandRotation}deg)`;
hourHand.style.transform = `rotate(${hourHandRotation}deg)`;
setTimeout(updateClock, 1000);
}
updateClock();
</script>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
position: relative;
}
.hour-hand,
.minute-hand,
.second-hand {
position: absolute;
background-color: black;
transform-origin: bottom center;
}
.hour-hand {
width: 4px;
height: 75px;
top: 50%;
left: 50%;
margin: -75px -2px 0;
}
.minute-hand {
width: 2px;
height: 95px;
top: 50%;
left: 50%;
margin: -95px -1px 0;
}
.second-hand {
width: 1px;
height: 105px;
top: 50%;
left: 50%;
margin: -105px;
}
</style>
</body>
</html>
6.0版本
这跟第一版有区别吗?而且404天什么鬼呀喂!
于是我告诉gpt:(恶魔低语)
秒针的对准还是不正确,而且我希望在表盘内部能够加上1到12的时间
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年时钟倒计时</title>
</head>
<body>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
</div>
<div id="countdown"></div>
<script>
function updateClock() {
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
const secondHand = document.querySelector(".second-hand");
const minuteHand = document.querySelector(".minute-hand");
const hourHand = document.querySelector(".hour-hand");
const secondHandRotation = seconds * 6;
const minuteHandRotation = (minutes * 6) + (seconds / 10);
const hourHandRotation = (hours * 30) + (minutes / 2);
secondHand.style.transform = `rotate(${secondHandRotation}deg) translateX(-50%)`;
minuteHand.style.transform = `rotate(${minuteHandRotation}deg) translateX(-50%)`;
hourHand.style.transform = `rotate(${hourHandRotation}deg) translateX(-50%)`;
setTimeout(updateClock, 1000);
}
function updateCountdown() {
const countdown = document.getElementById("countdown");
const now = new Date();
const newYear = new Date(now.getFullYear() + 1, 1, 10); // 下一年的2月10日作为新年时间
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
countdown.innerHTML = `距离新年还有 ${days} 天, ${hours} 小时, ${minutes} 分钟, ${seconds} 秒`;
setTimeout(updateCountdown, 1000);
}
updateClock();
updateCountdown();
</script>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
position: relative;
}
.hour-hand, .minute-hand, .second-hand {
position: absolute;
background-color: black;
transform-origin: bottom center;
}
.hour-hand {
width: 4px;
height: 75px;
top: 50%;
left: 50%;
margin: -75px -2px 0;
}
.minute-hand {
width: 2px;
height: 95px;
top: 50%;
left: 50%;
margin: -95px -1px 0;
}
.second-hand {
width: 1px;
height: 105px;
top: 50%;
left: 50%;
margin: -105px;
}
</style>
</body>
</html>
7.0版本
没什么改进,不过时间已经过去一个多小时了,快四点了。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>新年时钟倒计时</title>
</head>
<body>
<div class="clock">
<div class="hour-hand"></div>
<div class="minute-hand"></div>
<div class="second-hand"></div>
<div class="hour-mark"></div>
<div class="minute-mark"></div>
</div>
<div id="countdown"></div>
<script>
function updateClock() {
const now = new Date();
const seconds = now.getSeconds();
const minutes = now.getMinutes();
const hours = now.getHours();
const secondHand = document.querySelector(".second-hand");
const minuteHand = document.querySelector(".minute-hand");
const hourHand = document.querySelector(".hour-hand");
const secondHandRotation = seconds * 6;
const minuteHandRotation = (minutes * 6) + (seconds / 10);
const hourHandRotation = (hours * 30) + (minutes / 2);
secondHand.style.transform = `rotate(${secondHandRotation}deg) translateX(-50%)`;
minuteHand.style.transform = `rotate(${minuteHandRotation}deg) translateX(-50%)`;
hourHand.style.transform = `rotate(${hourHandRotation}deg) translateX(-50%)`;
setTimeout(updateClock, 1000);
}
function updateCountdown() {
const countdown = document.getElementById("countdown");
const now = new Date();
const newYear = new Date(now.getFullYear() + 1, 1, 10); // 下一年的2月10日作为新年时间
const timeLeft = newYear - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 * 24));
const hours = Math.floor((timeLeft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((timeLeft % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((timeLeft % (1000 * 60)) / 1000);
countdown.innerHTML = `距离新年还有 ${days} 天, ${hours} 小时, ${minutes} 分钟, ${seconds} 秒`;
setTimeout(updateCountdown, 1000);
}
updateClock();
updateCountdown();
</script>
<style>
.clock {
width: 200px;
height: 200px;
border: 2px solid black;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
position: relative;
}
.hour-hand, .minute-hand, .second-hand {
position: absolute;
background-color: black;
transform-origin: bottom center;
}
.hour-hand {
width: 4px;
height: 75px;
top: 50%;
left: 50%;
margin: -75px -2px 0;
}
.minute-hand {
width: 2px;
height: 95px;
top: 50%;
left: 50%;
margin: -95px -1px 0;
}
.second-hand {
width: 1px;
height: 105px;
top: 50%;
left: 50%;
margin: -105px;
}
.hour-mark {
position: absolute;
width: 2px;
height: 30px;
background-color: black;
top: 10px;
left: calc(50% - 1px);
transform-origin: bottom center;
}
.minute-mark {
position: absolute;
width: 1px;
height: 15px;
background-color: black;
top: 10px;
left: calc(50% - 0.5px);
transform-origin: bottom center;
}
</style>
</body>
</html>
调不动了,@u@。。。今天就先这样吧~白~本喵还是驯服不了ai啊喵!明天再继续>o<
又活了一天,已经很厉害了。