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>

相关推荐
袁煦丞11 分钟前
2025.8.18实验室【代码跑酷指南】Jupyter Notebook程序员的魔法本:cpolar内网穿透实验室第622个成功挑战
前端·程序员·远程工作
Joker Zxc16 分钟前
【前端基础】flex布局中使用`justify-content`后,最后一行的布局问题
前端·css
无奈何杨19 分钟前
风控系统事件分析中心,关联关系、排行、时间分布
前端·后端
Moment25 分钟前
nginx 如何配置防止慢速攻击 🤔🤔🤔
前端·后端·nginx
晓得迷路了30 分钟前
栗子前端技术周刊第 94 期 - React Native 0.81、jQuery 4.0.0 RC1、Bun v1.2.20...
前端·javascript·react.js
江城开朗的豌豆31 分钟前
React Native 实战心得
javascript
前端小巷子32 分钟前
Vue 自定义指令
前端·vue.js·面试
玲小珑38 分钟前
Next.js 教程系列(二十七)React Server Components (RSC) 与未来趋势
前端·next.js
Mike_jia38 分钟前
UptimeRobot API状态监控:零成本打造企业级业务健康看板
前端
江城开朗的豌豆39 分钟前
React状态更新踩坑记:我是这样优雅修改参数的
前端·javascript·react.js