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>

相关推荐
rising start4 分钟前
前端基础一、HTML5
前端·html·html5
Never_Satisfied13 分钟前
在JavaScript / HTML中,div容器在内容过多时不显示超出的部分
开发语言·javascript·html
鬼谷中妖13 分钟前
JavaScript 循环与对象:深入理解 for、for...in、for...of、不可枚举属性与可迭代对象
前端
大厂码农老A18 分钟前
你打的日志,正在拖垮你的系统:从P4小白到P7专家都是怎么打日志的?
java·前端·后端
im_AMBER20 分钟前
CSS 01【基础语法学习】
前端·css·笔记·学习
DokiDoki之父23 分钟前
前端速通—CSS篇
前端·css
pixle027 分钟前
Web大屏适配终极方案:vw/vh + flex + clamp() 完美组合
前端·大屏适配·vw/vh·clamp·终极方案·web大屏
ssf198733 分钟前
前后端分离项目前端页面开发远程调试代理解决跨域问题方法
前端
@PHARAOH33 分钟前
WHAT - 前端性能指标(加载性能指标)
前端
尘世中一位迷途小书童38 分钟前
🎨 SCSS 高级用法完全指南:从入门到精通
前端·css·开源