详情
评论
问答

一个动态的HTML时钟样式【HTML时钟样式】

效果:

图片[1]-欢迎各位,本站专注于收集分享各种最新资源、技术教程、绿色软件、还有来自全网的网站模板、网站源码分享以及各种去广告软件下载一个动态的HTML时钟样式
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QFY侧栏时钟</title>
    <style>
        .dynamic-clock {
            background: linear-gradient(135deg, #6e8efb, #a777e3);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            margin: 20px auto;
            max-width: 500px;
            color: white;
            font-family: 'Microsoft YaHei', sans-serif;
            position: relative;
            overflow: hidden;
        }
        .dynamic-clock::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 70%);
            animation: rotate 20s linear infinite;
            z-index: 0;
        }
        @keyframes rotate {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .clock-container { position: relative; z-index: 1; }
        .year-display {
            text-align: center;
            font-size: 1.3em;
            margin-bottom: 5px;
            font-weight: 600;
            display: flex;
            justify-content: center;
            gap: 15px;
        }
        .time-section { text-align: center; margin-bottom: 15px; }
        .time-display {
            font-size: 3.5em;
            font-weight: 300;
            letter-spacing: 2px;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .time-display span { margin: 0 5px; }
        .colon {
            animation: pulse 1s infinite;
            position: relative;
            top: -5px;
        }
        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }
        .date-section {
            display: flex;
            justify-content: space-between;
            margin: 15px 0;
            font-size: 1.1em;
            background: rgba(255, 255, 255, 0.15);
            padding: 12px;
            border-radius: 10px;
            backdrop-filter: blur(5px);
        }
        .date-item { text-align: center; flex: 1; }
        .date-label {
            font-size: 0.8em;
            opacity: 0.8;
            margin-bottom: 5px;
        }
        .date-value { font-weight: 600; }
        .greeting-section {
            text-align: center;
            margin: 20px 0 10px;
            padding-top: 15px;
            border-top: 1px solid rgba(255, 255, 255, 0.2);
        }
        .greeting-text {
            font-size: 1.5em;
            font-weight: 500;
            margin-bottom: 8px;
        }
        .greeting-tip {
            font-size: 0.95em;
            opacity: 0.9;
            line-height: 1.5;
            margin-bottom: 15px;
        }
        .next-festival {
            background: rgba(0, 0, 0, 0.1);
            padding: 10px;
            border-radius: 8px;
            font-size: 0.95em;
            margin-top: 10px;
        }
        .festival-message { font-weight: 600; }
        body.dark-theme  .dynamic-clock {
            background: linear-gradient(135deg, #434343, #000000);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
        }
    </style>
</head>
<body>
    <div class="dynamic-clock">
        <div class="clock-container">
            <div class="year-display">
                <span>2025年</span>
                <span>乙巳年</span>
                <span>蛇年</span>
            </div>
            
            <div class="time-section">
                <div class="time-display">
                    <span id="hours">13</span>
                    <span class="colon">:</span>
                    <span id="minutes">36</span>
                    <span class="colon">:</span>
                    <span id="seconds">00</span>
                </div>
            </div>
            
            <div class="date-section">
                <div class="date-item">
                    <div class="date-label">公历日期</div>
                    <div class="date-value" id="solar-date">9月26日</div>
                </div>
                <div class="date-item">
                    <div class="date-label">农历日期</div>
                    <div class="date-value" id="lunar-date">八月初五</div>
                </div>
                <div class="date-item">
                    <div class="date-label">星期</div>
                    <div class="date-value" id="weekday">星期五</div>
                </div>
            </div>
            
            <div class="greeting-section">
                <div class="greeting-text" id="greeting">下午好</div>
                <div class="greeting-tip" id="tip">金秋时节,愿您收获满满</div>
                <div class="next-festival" id="next-festival">
                    <div class="festival-message">距离国庆节还有5天</div>
                </div>
            </div>
        </div>
    </div>
 
    <script>
        // 2025年重要节日(国家授时中心数据)
        const festivals = [
            { name: "国庆节", date: new Date(2025, 9, 1), message: "🇨🇳 国庆快乐!盛世华诞,普天同庆" },
            { name: "中秋节", date: new Date(2025, 9, 6), message: "🎑 中秋快乐!月圆人团圆" },
            { name: "元旦", date: new Date(2026, 0, 1), message: "🎉 元旦快乐!新年新气象" },
            { name: "春节", date: new Date(2026, 1, 17), message: "🧧 春节快乐!乙巳年大吉" }
        ];
 
        function updateTime() {
            const now = new Date();
            const hours = now.getHours(); 
            
            // 更新时间显示 
            document.getElementById('hours').textContent  = hours.toString().padStart(2,'0'); 
            document.getElementById('minutes').textContent  = now.getMinutes().toString().padStart(2,'0'); 
            document.getElementById('seconds').textContent  = now.getSeconds().toString().padStart(2,'0'); 
            
            // 更新日期显示 
            document.getElementById('solar-date').textContent  = `${now.getMonth()+1} 月${now.getDate()} 日`;
            document.getElementById('weekday').textContent  = ['日','一','二','三','四','五','六'][now.getDay()];
            
            // 更新问候语 
            updateGreeting(hours);
            // 更新节日提醒 
            updateFestivalReminder(now);
        }
 
        function updateGreeting(hours) {
            let greeting, tip;
            if (hours < 5) {
                greeting = "深夜好";
                tip = "夜深人静,注意休息";
            } else if (hours < 8) {
                greeting = "清晨好";
                tip = "晨光熹微,一日之计在于晨";
            } else if (hours < 11) {
                greeting = "上午好";
                tip = "精力充沛,工作顺利";
            } else if (hours < 13) {
                greeting = "中午好";
                tip = "午间小憩,补充能量";
            } else if (hours < 18) {
                greeting = "下午好";
                tip = "金秋时节,愿您收获满满";
            } else if (hours < 22) {
                greeting = "晚上好";
                tip = "华灯初上,享受闲暇时光";
            } else {
                greeting = "夜深了";
                tip = "早睡早起,养生之道";
            }
            document.getElementById('greeting').textContent  = greeting;
            document.getElementById('tip').textContent  = tip;
        }
 
        function updateFestivalReminder(now) {
            const oneDay = 24 * 60 * 60 * 1000;
            let nextFestival = null;
            let minDays = Infinity;
            
            // 找出最近的未来节日 
            festivals.forEach(fest  => {
                const diffDays = Math.ceil((fest.date  - now) / oneDay);
                if (diffDays >= 0 && diffDays < minDays) {
                    minDays = diffDays;
                    nextFestival = fest;
                }
            });
            
            // 更新显示 
            const festivalEl = document.getElementById('next-festival'); 
            if (nextFestival) {
                if (minDays === 0) {
                    festivalEl.innerHTML  = `<div class="festival-message">${nextFestival.message}</div>`; 
                } else {
                    festivalEl.innerHTML  = `<div class="festival-message">距离${nextFestival.name} 还有${minDays}天</div>`;
                }
            } else {
                festivalEl.style.display  = 'none';
            }
        }
 
        // 初始化 
        document.addEventListener('DOMContentLoaded',  () => {
            updateTime();
            setInterval(updateTime, 1000);
            
            // 暗色模式适配 
            if (window.matchMedia('(prefers-color-scheme:  dark)').matches) {
                document.body.classList.add('dark-theme'); 
            }
        });
    </script>
</body>
</html>

效果:

图片[2]-欢迎各位,本站专注于收集分享各种最新资源、技术教程、绿色软件、还有来自全网的网站模板、网站源码分享以及各种去广告软件下载一个动态的HTML时钟样式
图片[3]-欢迎各位,本站专注于收集分享各种最新资源、技术教程、绿色软件、还有来自全网的网站模板、网站源码分享以及各种去广告软件下载一个动态的HTML时钟样式
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QFY侧栏时钟</title>
<style>
.dynamic-clock {
background: white;
border-radius: 20px;
padding: 30px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
margin: 20px auto;
max-width: 500px;
color: #333;
font-family: 'Microsoft YaHei', sans-serif;
position: relative;
overflow: hidden;
}
.dynamic-clock::before {
content: '';
position: absolute;
top: -50%;
left: -50%;
width: 200%;
height: 200%;
background: radial-gradient(circle, rgba(0,0,0,0.05) 0%, rgba(0,0,0,0) 70%);
animation: rotate 20s linear infinite;
z-index: 0;
}
@keyframes rotate {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.clock-container { position: relative; z-index: 1; }
.year-display {
text-align: center;
font-size: 1.3em;
margin-bottom: 5px;
font-weight: 600;
display: flex;
justify-content: center;
gap: 15px;
}
.time-section { text-align: center; margin-bottom: 15px; }
.time-display {
font-size: 3.5em;
font-weight: 300;
letter-spacing: 2px;
display: flex;
justify-content: center;
align-items: center;
}
.time-display span { margin: 0 5px; }
.colon {
animation: pulse 1s infinite;
position: relative;
top: -5px;
}
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.5; }
}
.date-section {
display: flex;
justify-content: space-between;
margin: 15px 0;
font-size: 1.1em;
background: rgba(0, 0, 0, 0.03);
padding: 12px;
border-radius: 10px;
}
.date-item { text-align: center; flex: 1; }
.date-label {
font-size: 0.8em;
opacity: 0.8;
margin-bottom: 5px;
}
.date-value { font-weight: 600; }
.greeting-section {
text-align: center;
margin: 20px 0 10px;
padding-top: 15px;
border-top: 1px solid rgba(0, 0, 0, 0.1);
}
.greeting-text {
font-size: 1.5em;
font-weight: 500;
margin-bottom: 8px;
}
.greeting-tip {
font-size: 0.95em;
opacity: 0.9;
line-height: 1.5;
margin-bottom: 15px;
}
.next-festival {
padding: 10px;
border-radius: 8px;
font-size: 0.95em;
margin-top: 10px;
}
.festival-message { font-weight: 600; }
body.dark-theme  .dynamic-clock {
background: linear-gradient(135deg, #434343, #000000);
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
color: white;
}
body.dark-theme  .date-section {
background: rgba(255, 255, 255, 0.15);
}
body.dark-theme  .greeting-section {
border-top: 1px solid rgba(255, 255, 255, 0.2);
}
body.dark-theme  .next-festival {
background: rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="dynamic-clock">
<div class="clock-container">
<div class="year-display">
<span>2025年</span>
<span>乙巳年</span>
<span>蛇年</span>
</div>
 
<div class="time-section">
<div class="time-display">
<span id="hours">13</span>
<span class="colon">:</span>
<span id="minutes">36</span>
<span class="colon">:</span>
<span id="seconds">00</span>
</div>
</div>
 
<div class="date-section">
<div class="date-item">
<div class="date-label">公历日期</div>
<div class="date-value" id="solar-date">9月26日</div>
</div>
<div class="date-item">
<div class="date-label">农历日期</div>
<div class="date-value" id="lunar-date">八月初五</div>
</div>
<div class="date-item">
<div class="date-label">星期</div>
<div class="date-value" id="weekday">星期五</div>
</div>
</div>
 
<div class="greeting-section">
<div class="greeting-text" id="greeting">下午好</div>
<div class="greeting-tip" id="tip">金秋时节,愿您收获满满</div>
<div class="next-festival" id="next-festival">
<div class="festival-message">距离国庆节还有5天</div>
</div>
</div>
</div>
</div>
 
<script>
// 2025年重要节日(国家授时中心数据)
const festivals = [
{ name: "国庆节", date: new Date(2025, 9, 1), message: "🇨🇳 国庆快乐!盛世华诞,普天同庆" },
{ name: "中秋节", date: new Date(2025, 9, 6), message: "🎑 中秋快乐!月圆人团圆" },
{ name: "元旦", date: new Date(2026, 0, 1), message: "🎉 元旦快乐!新年新气象" },
{ name: "春节", date: new Date(2026, 1, 17), message: "🧧 春节快乐!乙巳年大吉" }
];
 
function updateTime() {
const now = new Date();
const hours = now.getHours(); 
 
// 更新时间显示
document.getElementById('hours').textContent  = hours.toString().padStart(2,'0'); 
document.getElementById('minutes').textContent  = now.getMinutes().toString().padStart(2,'0'); 
document.getElementById('seconds').textContent  = now.getSeconds().toString().padStart(2,'0'); 
 
// 更新日期显示
document.getElementById('solar-date').textContent  = `${now.getMonth()+1}  月${now.getDate()}  日`;
document.getElementById('weekday').textContent  = ['日','一','二','三','四','五','六'][now.getDay()];
 
// 更新问候语
updateGreeting(hours);
// 更新节日提醒
updateFestivalReminder(now);
}
 
function updateGreeting(hours) {
let greeting, tip;
if (hours < 5) {
greeting = "深夜好";
tip = "夜深人静,注意休息";
} else if (hours < 8) {
greeting = "清晨好";
tip = "晨光熹微,一日之计在于晨";
} else if (hours < 11) {
greeting = "上午好";
tip = "精力充沛,工作顺利";
} else if (hours < 13) {
greeting = "中午好";
tip = "午间小憩,补充能量";
} else if (hours < 18) {
greeting = "下午好";
tip = "金秋时节,愿您收获满满";
} else if (hours < 22) {
greeting = "晚上好";
tip = "华灯初上,享受闲暇时光";
} else {
greeting = "夜深了";
tip = "早睡早起,养生之道";
}
document.getElementById('greeting').textContent  = greeting;
document.getElementById('tip').textContent  = tip;
}
 
function updateFestivalReminder(now) {
const oneDay = 24 * 60 * 60 * 1000;
let nextFestival = null;
let minDays = Infinity;
 
// 找出最近的未来节日 
festivals.forEach(fest  => {
const diffDays = Math.ceil((fest.date  - now) / oneDay);
if (diffDays >= 0 && diffDays < minDays) {
minDays = diffDays;
nextFestival = fest;
}
});
 
// 更新显示 
const festivalEl = document.getElementById('next-festival'); 
if (nextFestival) {
if (minDays === 0) {
festivalEl.innerHTML  = `<div class="festival-message">${nextFestival.message}</div>`; 
} else {
festivalEl.innerHTML  = `<div class="festival-message">距离${nextFestival.name}  还有${minDays}天</div>`;
}
} else {
festivalEl.style.display  = 'none';
}
}
 
// 初始化
document.addEventListener('DOMContentLoaded',  () => {
updateTime();
setInterval(updateTime, 1000);
 
// 暗色模式适配
if (window.matchMedia('(prefers-color-scheme:  dark)').matches) {
document.body.classList.add('dark-theme'); 
}
});
</script>
</body>
</html>
温馨提示: 本文最后更新于2025-09-27 06:36:10,某些文章具有时效性,若有错误或已失效,请在下方 留言或联系 小哥互联
© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容