<!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 {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
box-sizing: border-box;
}
.header {
background-color: #88001b;
color: white;
height: 180px;
display: flex;
justify-content: center;
align-items: center;
font-size: 100px;
}
.timer {
display: flex;
justify-content: center;
align-items: center;
height: calc(100vh - 280px);
font-size: 30vw;
}
.buttons {
position: fixed;
bottom: 0;
width: 100%;
display: flex;
justify-content: space-around;
padding: 10px 0;
}
button {
font-size: 20px;
padding: 10px 20px;
}
</style>
</head>
<body>
<div class="header">比赛倒计时</div>
<div class="timer" id="timer">01:00</div>
<div class="buttons">
<button id="startTimer">开始计时</button>
<button id="pauseTimer">暂停计时</button>
<button id="fullscreenToggle">全屏显示</button>
<button id="clearData">清空数据</button>
<button id="customTime">自定义时间</button>
</div>
<audio id="startSound" src="start-timer-sound.mp3"></audio>
<audio id="warningSound" src="warning-timer-sound.mp3"></audio>
<script>
let totalSeconds = 60;
let countdown;
let warningPlayed = false;
let isPaused = false;
function startTimer() {
document.getElementById('startSound').play();
if (!countdown && !isPaused) {
countdown = setInterval(timerFunction, 1000);
} else if (isPaused) {
countdown = setInterval(timerFunction, 1000);
isPaused = false;
}
}
function pauseTimer() {
clearInterval(countdown);
countdown = null;
isPaused = true;
}
function timerFunction() {
if (!isPaused) {
totalSeconds--;
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
document.getElementById('timer').textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
if (totalSeconds === 10 && !warningPlayed) {
document.getElementById('warningSound').play();
warningPlayed = true;
}
if (totalSeconds <= 0) {
clearInterval(countdown);
document.getElementById('timer').textContent = "时间到";
}
}
}
// 按空格键开始或暂停计时
document.addEventListener('keydown', function (event) {
if (event.code === 'Space') {
event.preventDefault();
if (!countdown || isPaused) {
startTimer();
} else {
pauseTimer();
}
}
});
// 按回车键清空数据
document.getElementById('clearData').addEventListener('click', function () {
totalSeconds = 60;
clearInterval(countdown);
countdown = null;
isPaused = false;
document.getElementById('timer').textContent = "01:00";
});
// 弹出自定义时间对话框
document.getElementById('customTime').addEventListener('click', function () {
const inputTime = prompt('请输入倒计时时间(单位:秒)');
const time = parseInt(inputTime);
if (isNaN(time)) {
alert('输入的时间无效,请输入一个有效的数字');
} else {
totalSeconds = time;
document.getElementById('timer').textContent = `${String(Math.floor(time / 60)).padStart(2, '0')}:${String(time % 60).padStart(2, '0')}`;
if (document.fullscreenElement) {
document.exitFullscreen();
}
}
});
document.getElementById('startTimer').addEventListener('click', startTimer);
document.getElementById('pauseTimer').addEventListener('click', pauseTimer);
document.getElementById('fullscreenToggle').addEventListener('click', function () {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen().then(() => {
this.textContent = '退出全屏模式';
}).catch(err => {
alert(`无法进入全屏模式: ${err.message}`);
});
} else {
if (document.exitFullscreen) {
document.exitFullscreen().then(() => {
this.textContent = '全屏显示';
}).catch(err => {
alert(`无法退出全屏模式: ${err.message}`);
});
}
}
});
</script>
</body>
</html>
没有合适的资源?快使用搜索试试~ 我知道了~
比赛倒计时2.0《大字体显示比赛倒计时器PRO》是一款简洁实用的倒计时软件.rar
共8个文件
html:4个
mp3:2个
exe:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 72 浏览量
2024-04-30
15:38:57
上传
评论
收藏 1.5MB RAR 举报
温馨提示
【倒计时计时器】是一个简单易用的网页应用,可以帮助用户进行倒计时计时的操作。以下是升级后的内容:1. 新增暂停功能:现在可以在倒计时进行中暂停计时,再次点击开始按钮可以继续计时。2. 添加全屏显示按钮:在全屏模式下更好地展示倒计时器,提供更好的用户体验。3. 自定义输入倒计时时间:用户可以根据需求自行输入倒计时时间,以秒为单位。4. 使用空格键控制计时开始和暂停:按下键盘上的空格键可以快速开始或暂停计时。5. 使用回车键清空数据:按下回车键可以快速清空倒计时数据,重新开始倒计时。6. 修改界面样式:将倒计时器的背景色设置为黑色,字体颜色设置为醒目的红色,使其更加突出和易于辨识。 这些升级内容使得倒计时计时器更加功能完善、易于使用,并提供了更多的定制化选项和交互方式,以满足用户的需求。
资源推荐
资源详情
资源评论
收起资源包目录
比赛倒计时2.0《大字体显示比赛倒计时器PRO》是一款简洁实用的倒计时软件.rar (8个子文件)
比赛倒计时2.0《大字体显示比赛倒计时器PRO》是一款简洁实用的倒计时软件
比赛倒计时正式PRO(黑底红字).html 5KB
原始全屏版.html 4KB
原始非全屏版.html 3KB
比赛倒计时正式PRO.html 5KB
warning-timer-sound.mp3 166KB
电脑桌面倒计时软件.exe 1.31MB
djs
start-timer-sound.mp3 23KB
全屏幕倒计时秒表软件.exe 136KB
共 8 条
- 1
资源评论
大飞哥软件自习室
- 粉丝: 480
- 资源: 1299
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Picasso_v3.1 2.ipa
- chromedriver-mac-arm64.zip
- 蓝zapro.apk
- chromedriver-linux64.zip
- UCAS研一深度学习实验-MNIST手写数字识别python源码+详细注释(高分项目)
- 基于Python和PyTorch框架完成的一个手写数字识别实验源码(带MINIST手写数字数据集)+详细注释(高分项目)
- 基于Matlab在MNIST数据集上利用CNN完成手写体数字识别任务,并实现单层CNN反向传播算法+源代码+文档说明(高分项目)
- NVIDIA驱动、CUDA和Pytorch及其依赖
- 基于SVM多特征融合的微表情识别python源码+项目说明+详细注释(高分课程设计)
- html动态爱心代码一(附源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功