开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
30.html 6.41 KB
一键复制 编辑 原始数据 按行查看 历史
弦中落宫商 提交于 2023年07月11日 14:30 +08:00 . 添加案例: 日期工具 - 倒计时
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>日期工具 - 倒计时</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container { max-width: 900px; margin: 0 auto; }
h1 { text-align: center; color: #fff; margin-bottom: 30px; font-size: 2rem; }
.section {
background: #fff;
border-radius: 15px;
padding: 25px;
margin-bottom: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.section h2 { color: #667eea; margin-bottom: 15px; font-size: 1.3rem; }
.code-block {
background: #f8f9fa;
border-left: 4px solid #667eea;
padding: 15px;
border-radius: 0 8px 8px 0;
margin: 15px 0;
font-family: monospace;
font-size: 0.85rem;
}
.input-group { margin: 15px 0; }
.input-group label { display: block; margin-bottom: 8px; color: #333; font-weight: bold; }
.input-group input {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 8px;
font-size: 1rem;
}
.btn {
background: linear-gradient(90deg, #667eea, #764ba2);
border: none;
color: #fff;
padding: 12px 25px;
border-radius: 8px;
cursor: pointer;
font-size: 1rem;
margin: 5px;
}
.result-box {
background: #f0f4ff;
border: 2px solid #667eea;
border-radius: 10px;
padding: 20px;
margin-top: 20px;
}
.result-box h3 { color: #667eea; margin-bottom: 10px; }
.countdown-display {
background: #f8f9fa;
padding: 15px;
border-radius: 8px;
margin: 10px 0;
font-family: monospace;
font-size: 1.1rem;
}
.countdown-time {
background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
color: #fff;
padding: 30px;
border-radius: 15px;
text-align: center;
margin: 20px 0;
font-size: 2rem;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>日期工具 - 倒计时</h1>
<div class="section">
<h2>倒计时</h2>
<div class="input-group">
<label>目标日期:</label>
<input type="datetime-local" id="targetDate" />
</div>
<button class="btn" onclick="startCountdown()">开始倒计时</button>
<button class="btn" onclick="stopCountdown()">停止倒计时</button>
<div class="result-box" id="resultBox" style="display:none;">
<h3>倒计时结果</h3>
<div class="countdown-time" id="countdownTime">00:00:00:00</div>
<div class="countdown-display" id="countdownResult"></div>
</div>
</div>
<div class="section">
<h2>倒计时方法实现</h2>
<div class="code-block">
// 倒计时函数<br>
function countdown(targetDate) {<br>
&nbsp;&nbsp;const now = new Date();<br>
&nbsp;&nbsp;const target = new Date(targetDate);<br>
&nbsp;&nbsp;const diff = target - now;<br><br>
&nbsp;&nbsp;if (diff <= 0) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;return { days: 0, hours: 0, minutes: 0, seconds: 0 };<br>
&nbsp;&nbsp;}<br><br>
&nbsp;&nbsp;const days = Math.floor(diff / (1000 * 60 * 60 * 24));<br>
&nbsp;&nbsp;const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));<br>
&nbsp;&nbsp;const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));<br>
&nbsp;&nbsp;const seconds = Math.floor((diff % (1000 * 60)) / 1000);<br><br>
&nbsp;&nbsp;return { days, hours, minutes, seconds };<br>
}
</div>
</div>
</div>
<script>
let countdownInterval;
function startCountdown() {
const targetDateInput = document.getElementById('targetDate').value;
if (!targetDateInput) {
alert('请选择目标日期');
return;
}
const targetDate = new Date(targetDateInput);
document.getElementById('resultBox').style.display = 'block';
if (countdownInterval) clearInterval(countdownInterval);
countdownInterval = setInterval(() => {
const result = countdown(targetDate);
const { days, hours, minutes, seconds } = result;
document.getElementById('countdownTime').textContent =
`${String(days).padStart(2, '0')}:${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
document.getElementById('countdownResult').innerHTML =
`${days}${hours}小时 ${minutes}${seconds}秒`;
if (days === 0 && hours === 0 && minutes === 0 && seconds === 0) {
clearInterval(countdownInterval);
alert('倒计时结束!');
}
}, 1000);
}
function stopCountdown() {
if (countdownInterval) {
clearInterval(countdownInterval);
countdownInterval = null;
}
}
function countdown(targetDate) {
const now = new Date();
const diff = targetDate - now;
if (diff <= 0) {
return { days: 0, hours: 0, minutes: 0, seconds: 0 };
}
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
return { days, hours, minutes, seconds };
}
</script>
</body>
</html>
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

HTML + javascript页面效果案例
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/wangxios/workspace_javascript.git
git@gitee.com:wangxios/workspace_javascript.git
wangxios
workspace_javascript
JavaScript案例合集
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /