Skip to content
0

迎春计时

春洁计时器

html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>🏮新桃辞旧 · 岁华录 🎋</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-color: #d32f2f;
            --secondary-color: #ffb300;
            --background-color: #3d0007;
            --text-color: #ffffff;
            --panel-bg: rgba(60, 0, 5, 0.85);
            --shadow-color: rgba(0, 0, 0, 0.6);
            --canvas-fade: rgba(61, 0, 7, 0.2);
            --box-label-color: #ffcf6d; /* 固定亮金色,解决看不到字的问题 */
        }

        /* --- 四大主题精准适配 --- */
        .theme-traditional {
            --primary-color: #d32f2f;
            --secondary-color: #ffb300;
            --background-color: #3d0007;
            --text-color: #ffffff;
            --panel-bg: rgba(60, 0, 5, 0.85);
            --shadow-color: rgba(0, 0, 0, 0.5);
            --canvas-fade: rgba(61, 0, 7, 0.2);
        }

        .theme-gold {
            --primary-color: #ffca28;
            --secondary-color: #ffecb3;
            --background-color: #1a1000;
            --text-color: #ffecb3;
            --panel-bg: rgba(45, 30, 0, 0.9);
            --shadow-color: rgba(0, 0, 0, 0.8);
            --canvas-fade: rgba(26, 16, 0, 0.2);
        }

        .theme-ink {
            --primary-color: #1a1a1a;
            --secondary-color: #d32f2f;
            --background-color: #f0f0f0;
            --text-color: #1a1a1a;
            --panel-bg: rgba(255, 255, 255, 0.95);
            --shadow-color: rgba(0, 0, 0, 0.1);
            --canvas-fade: rgba(240, 240, 240, 0.2);
        }

        .theme-orange {
            --primary-color: #e65100;
            --secondary-color: #bf360c;
            --background-color: #fff3e0;
            --text-color: #4e342e;
            --panel-bg: rgba(255, 240, 220, 0.9);
            --shadow-color: rgba(255, 255, 255, 0.2);
            --canvas-fade: rgba(255, 243, 224, 0.2);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'STKaiti', 'Microsoft YaHei', sans-serif;
            background-color: var(--background-color);
            color: var(--text-color);
            min-height: 100vh;
            overflow-x: hidden;
            transition: all 0.6s ease;
            display: flex;
            flex-direction: column;
        }

        #canvas-stage {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 1;
            pointer-events: none;
        }

        .container {
            position: relative;
            z-index: 10;
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            padding: 40px 20px;
            pointer-events: none;
        }

        .container * {
            pointer-events: auto;
        }

        header {
            text-align: center;
            margin-bottom: 25px;
            width: 100%;
        }

        h1 {
            font-size: clamp(2.2rem, 8vw, 3.5rem);
            color: var(--secondary-color);
            text-shadow: 0 0 15px var(--shadow-color);
            letter-spacing: 5px;
            margin-bottom: 10px;
        }

        .theme-selector {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin-bottom: 20px;
            flex-wrap: wrap;
        }

        .theme-btn {
            padding: 8px 18px;
            border-radius: 25px;
            border: 1.5px solid var(--secondary-color);
            cursor: pointer;
            background: rgba(128, 128, 128, 0.15);
            color: var(--text-color);
            font-size: 0.9rem;
            transition: 0.3s;
            font-weight: bold;
        }

        .theme-btn.active {
            background: var(--primary-color);
            color: #fff;
            border-color: #fff;
            box-shadow: 0 0 10px var(--primary-color);
        }

        .subtitle {
            font-size: 1.4rem;
            color: var(--secondary-color);
            font-weight: bold;
            margin-bottom: 10px;
            letter-spacing: 2px;
        }

        .countdown-container {
            background: var(--panel-bg);
            backdrop-filter: blur(10px);
            padding: 40px;
            border-radius: 40px;
            border: 3px solid var(--secondary-color);
            box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
            text-align: center;
            width: 95%;
            max-width: 850px;
        }

        .date-display {
            font-size: clamp(1.4rem, 5vw, 1.8rem);
            color: var(--secondary-color);
            font-weight: bold;
            margin-bottom: 5px;
        }

        .lunar-date-row {
            font-size: clamp(1.1rem, 4vw, 1.5rem);
            color: var(--secondary-color);
            font-weight: bold;
            margin-bottom: 15px;
            opacity: 0.9;
        }

        .divider {
            width: 80%;
            height: 1.5px;
            background: var(--secondary-color);
            margin: 10px auto 25px;
            opacity: 0.3;
        }

        .countdown-row {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin: 20px 0;
        }

        .time-box {
            background: linear-gradient(135deg, var(--primary-color), #8b0000);
            flex: 1;
            padding: 25px 5px;
            border-radius: 25px;
            border: 1.5px solid var(--secondary-color);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
        }

        .time-val {
            font-size: 4rem;
            font-weight: 900;
            line-height: 1;
            color: #fff;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
        }

        /* 核心修正:天时分秒标签,强制亮金色,加文字阴影防重叠 */
        .time-lab {
            font-size: 1rem;
            color: #ffcf6d !important;
            margin-top: 10px;
            font-weight: bold;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
        }

        .lunar-tag {
            font-size: 1.6rem;
            color: var(--text-color);
            font-weight: bold;
            margin-top: 10px;
            letter-spacing: 2px;
        }

        footer {
            width: 100%;
            text-align: center;
            padding: 30px 0;
            z-index: 1000;
            pointer-events: none;
        }

        footer p {
            color: var(--text-color) !important;
            font-size: 1.1rem;
            font-weight: bold;
            text-shadow: 1px 1px 4px var(--shadow-color);
            letter-spacing: 1px;
        }

        .highlight {
            color: var(--secondary-color) !important;
        }
    </style>
</head>
<body class="theme-traditional">

<canvas id="canvas-stage"></canvas>

<div class="container">
    <header>
        <h1 id="year-title">春节倒计时</h1>
        <div class="theme-selector">
            <button class="theme-btn active" onclick="setTheme('traditional', this)">传统红</button>
            <button class="theme-btn" onclick="setTheme('gold', this)">富贵金</button>
            <button class="theme-btn" onclick="setTheme('ink', this)">水墨风</button>
            <button class="theme-btn" onclick="setTheme('orange', this)">喜洋洋</button>
        </div>
        <div class="subtitle" id="sub-info">吉星高照 · 阖家幸福</div>
    </header>

    <div class="countdown-container">
        <div class="date-display" id="full-date">加载中...</div>
        <div class="lunar-date-row" id="lunar-date-str">加载中...</div>
        <div class="divider"></div>
        <div class="countdown-row">
            <div class="time-box">
                <div class="time-val" id="days">00</div>
                <div class="time-lab">天</div>
            </div>
            <div class="time-box">
                <div class="time-val" id="hours">00</div>
                <div class="time-lab">时</div>
            </div>
            <div class="time-box">
                <div class="time-val" id="minutes">00</div>
                <div class="time-lab">分</div>
            </div>
            <div class="time-box">
                <div class="time-val" id="seconds">00</div>
                <div class="time-lab">秒</div>
            </div>
        </div>
        <div class="lunar-tag" id="lunar-text"></div>
    </div>

    <footer>
        <!-- 修正页脚:显示版权年份和春节倒计时 -->
        <p>© <span id="copy-year-val"></span> 春节倒计时 | 作者:<span class="highlight">Stara</span> | 祝您新春大吉</p>
    </footer>
</div>

<script>
    /** 精准日期数据 **/
    const CNY_DATA = {
        2025: {date: '2025-01-29', gz: '乙巳', ani: '蛇', emo: '🐍'},
        2026: {date: '2026-02-17', gz: '丙午', ani: '马', emo: '🐎'},
        2027: {date: '2027-02-06', gz: '丁未', ani: '羊', emo: '🐏'},
        2028: {date: '2028-01-26', gz: '戊申', ani: '猴', emo: '🐒'},
        2029: {date: '2029-02-13', gz: '己酉', ani: '鸡', emo: '🐔'},
        2030: {date: '2030-02-03', gz: '庚戌', ani: '狗', emo: '🐶'}
    };

    let targetDate, targetYear;

    function initTimer() {
        const now = new window.Date();
        let currentYear = now.getFullYear();
        let found = false;

        for (let y = currentYear; y <= 2030; y++) {
            let festival = new window.Date(CNY_DATA[y].date.replace(/-/g, '/') + ' 00:00:00');
            if (now.getTime() < festival.getTime()) {
                targetYear = y;
                targetDate = festival;
                found = true;
                break;
            }
        }

        if (!found) {
            targetYear = 2026;
            targetDate = new window.Date('2026/02/17 00:00:00');
        }

        const info = CNY_DATA[targetYear];
        document.getElementById('year-title').innerText = `${targetYear}年春节倒计时`;
        document.getElementById('sub-info').innerText = `农历${info.gz}${info.ani}年 · 吉星高照 · 阖家幸福`;
        document.getElementById('full-date').innerText = `${targetYear}年春节:${targetYear}年${targetDate.getMonth() + 1}月${targetDate.getDate()}日`;
        document.getElementById('lunar-date-str').innerText = `农历 ${info.gz}年 正月初一`;
        document.getElementById('lunar-text').innerText = `【 ${info.gz} · ${info.ani}年 】 ${info.emo}`;

        // 修正页脚年份
        document.getElementById('copy-year-val').innerText = now.getFullYear();
    }

    /** Canvas 特效引擎 **/
    const canvas = document.getElementById('canvas-stage');
    const ctx = canvas.getContext('2d');
    let particles = [];

    function resize() {
        canvas.width = window.innerWidth;
        canvas.height = window.innerHeight;
    }

    window.addEventListener('resize', resize);
    resize();

    class Particle {
        constructor(x, y, color, type) {
            this.x = x;
            this.y = y;
            this.color = color;
            this.type = type;
            this.life = 1;
            this.decay = Math.random() * 0.015 + 0.01;
            const angle = Math.random() * Math.PI * 2;
            const speed = type === 'firework' ? Math.random() * 7 + 2 : Math.random() * 4 + 2;
            this.vx = Math.cos(angle) * speed;
            this.vy = Math.sin(angle) * speed;
            this.gravity = 0.12;
        }

        update() {
            this.vx *= 0.97;
            this.vy *= 0.97;
            this.vy += this.gravity;
            this.x += this.vx;
            this.y += this.vy;
            this.life -= this.decay;
        }

        draw() {
            ctx.globalAlpha = this.life;
            ctx.fillStyle = this.color;
            ctx.beginPath();
            ctx.arc(this.x, this.y, 2, 0, Math.PI * 2);
            ctx.fill();
        }
    }

    function createExplosion(x, y, type) {
        const color = type === 'firework' ? `hsl(${Math.random() * 360}, 100%, 70%)` : '#FF3333';
        for (let i = 0; i < 50; i++) particles.push(new Particle(x, y, color, type));
        if (type === 'cracker') {
            ctx.fillStyle = 'rgba(255,255,255,0.15)';
            ctx.fillRect(0, 0, canvas.width, canvas.height);
        }
    }

    function loop() {
        const fadeColor = getComputedStyle(document.body).getPropertyValue('--canvas-fade').trim();
        ctx.fillStyle = fadeColor;
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        if (Math.random() < 0.05) {
            ctx.font = "24px STKaiti";
            ctx.fillStyle = "gold";
            ctx.fillText(["福", "春", "🧧", "🏮", "🎆", "🌸"][Math.floor(Math.random() * 6)], Math.random() * canvas.width, Math.random() * canvas.height);
        }
        particles.forEach((p, i) => {
            p.update();
            p.draw();
            if (p.life <= 0) particles.splice(i, 1);
        });
        requestAnimationFrame(loop);
    }

    setInterval(() => {
        const x = Math.random() * canvas.width;
        if (Math.random() > 0.45) createExplosion(x, Math.random() * canvas.height * 0.5, 'firework');
        else createExplosion(x, canvas.height * 0.8, 'cracker');
    }, 1600);

    function updateTime() {
        const now = new window.Date();
        const diff = targetDate.getTime() - now.getTime();
        if (diff <= 0) {
            initTimer();
            return;
        }
        const d = Math.floor(diff / (1000 * 60 * 60 * 24));
        const h = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        const m = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
        const s = Math.floor((diff % (1000 * 60)) / 1000);
        document.getElementById('days').innerText = d.toString().padStart(2, '0');
        document.getElementById('hours').innerText = h.toString().padStart(2, '0');
        document.getElementById('minutes').innerText = m.toString().padStart(2, '0');
        document.getElementById('seconds').innerText = s.toString().padStart(2, '0');
    }

    function setTheme(t, b) {
        document.querySelectorAll('.theme-btn').forEach(btn => btn.classList.remove('active'));
        b.classList.add('active');
        document.body.className = 'theme-' + t;
    }

    initTimer();
    loop();
    setInterval(updateTime, 1000);
    updateTime();
</script>
</body>
</html>
最近更新

留言交流

欢迎留下想法,理性友善交流