html+js+css在线倒计时

代码在图片后面 点赞加关注 谢谢大佬照顾😜

图例

时间到前

时间到后

源代码

<!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 {

display: flex;

justify-content: center;

align-items: center;

height: 100vh;

background-color: #f4f4f4;

margin: 0;

font-family: Arial, sans-serif;

}

.countdown-container {

text-align: center;

border-radius: 8px;

padding: 20px;

transition: border-color 0.3s ease;

}

h1 {

font-size: 2.5em;

color: #333;

margin-bottom: 20px;

text-align:center;

}

.time-left {

font-size: 1.8em;

color: #333;

border: 2px solid #4caf50;

padding: 10px;

border-radius: 8px;

}

.time-left.time-up {

border-color: #e74c3c;

}

</style>

</head>

<body>

<div class="countdown-container">

<p class="time-left">距离下班还1分钟</p>

</div>

<script>

const timeDisplay = document.querySelector('.time-left');

let countdown = 1 * 60; // 5 minutes in seconds

function updateCountdown() {

let minutes = Math.floor(countdown / 60);

let seconds = countdown % 60;

minutes = minutes < 10 ? '0' + minutes : minutes;

seconds = seconds < 10 ? '0' + seconds : seconds;

timeDisplay.textContent = `距离下班还有{minutes}:{seconds}`;

if (countdown <= 0) {

timeDisplay.classList.add('time-up');

clearInterval(intervalId);

}

countdown--;

}

const intervalId = setInterval(updateCountdown, 1000);

</script>

</body>

</html>

相关推荐
FRing0327 分钟前
vue3干货总结2(vue3生命周期、父子通信、模版引用、provide和inject)
开发语言·前端·vue.js·vue3
锋行天下2 小时前
langgraph 全栈项目(三)
前端·人工智能·后端
YIAN3 小时前
从 LangChain 到 DeepAgents:手把手拆解 createAgent、Middleware 与复杂 Agent
javascript·langchain·deepseek
锋行天下3 小时前
langgraph 全栈项目(二)
前端·人工智能·后端
冬夜Zis4 小时前
顺着作用域链和 outer 指针,一次性看懂闭包底层逻辑
javascript
Ceelog4 小时前
Mac 上怎么找出并安全清理旧的 node_modules?(实测 304 个占 66.3 GB)
javascript
锋行天下4 小时前
langgraph全栈项目(一)
前端·人工智能·后端
叼烟扛炮4 小时前
[LangChain] 学习笔记(15):为什么你的重试没用——429、抖动、fallback 与熔断
java·服务器·前端
小码哥0685 小时前
智慧物业系统源码定制:公告发布范围与住户阅读记录设计
前端·javascript·vue.js·物业管理·物业系统·物业软件