酷炫LED数字时钟

酷炫LED数字时钟的实现

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>酷炫LED数字时钟</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'Orbitron', sans-serif;
            overflow: hidden;
            color: #fff;
            position: relative;
        }
        
        /* 粒子背景效果 */
        .particles {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -1;
        }
        
        .particle {
            position: absolute;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.2);
            animation: float 15s infinite linear;
        }
        
        @keyframes float {
            0% {
                transform: translateY(0) translateX(0);
                opacity: 0;
            }
            10% {
                opacity: 1;
            }
            90% {
                opacity: 1;
            }
            100% {
                transform: translateY(-100vh) translateX(100px);
                opacity: 0;
            }
        }
        
        .container {
            text-align: center;
            background: rgba(0, 0, 0, 0.7);
            padding: 30px 40px;
            border-radius: 20px;
            box-shadow: 0 0 40px rgba(0, 200, 255, 0.5);
            position: relative;
            overflow: hidden;
            z-index: 10;
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }
        
        .container::before {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            bottom: -2px;
            background: linear-gradient(45deg, #ff0000, #ff7300, #fffb00, #48ff00, #00ffd5, #002bff, #7a00ff, #ff00c8, #ff0000);
            background-size: 400%;
            border-radius: 22px;
            z-index: -1;
            animation: glowing 20s linear infinite;
            opacity: 0.5;
        }
        
        @keyframes glowing {
            0% {
                background-position: 0 0;
            }
            50% {
                background-position: 400% 0;
            }
            100% {
                background-position: 0 0;
            }
        }
        
        h1 {
            font-size: 2.8rem;
            margin-bottom: 20px;
            color: #fff;
            text-shadow: 0 0 10px #00ffff, 0 0 20px #00ffff;
            letter-spacing: 3px;
        }
        
        .clock-container {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 15px;
            padding: 30px 0;
        }
        
        .digit-group {
            display: flex;
            gap: 10px;
        }
        
        .digit {
            width: 100px;
            height: 180px;
            position: relative;
        }
        
        .segment {
            position: absolute;
            background: rgba(0, 200, 255, 0.3);
            transition: all 0.3s ease;
            border-radius: 5px;
        }
        
        .segment.active {
            background: #00ffff;
            box-shadow: 0 0 15px #00ffff, 0 0 30px rgba(0, 255, 255, 0.5);
        }
        
        .segment-a { top: 0; left: 20px; right: 20px; height: 15px; }
        .segment-b { top: 20px; right: 0; width: 15px; height: 70px; }
        .segment-c { bottom: 20px; right: 0; width: 15px; height: 70px; }
        .segment-d { bottom: 0; left: 20px; right: 20px; height: 15px; }
        .segment-e { bottom: 20px; left: 0; width: 15px; height: 70px; }
        .segment-f { top: 20px; left: 0; width: 15px; height: 70px; }
        .segment-g { top: 50%; transform: translateY(-50%); left: 20px; right: 20px; height: 15px; }
        
        .colon {
            width: 20px;
            height: 180px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 50px;
        }
        
        .dot {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: rgba(0, 200, 255, 0.3);
            transition: all 0.3s ease;
        }
        
        .dot.active {
            background: #00ffff;
            box-shadow: 0 0 10px #00ffff;
        }
        
        .date-display {
            font-size: 1.8rem;
            margin-top: 25px;
            color: #fff;
            text-shadow: 0 0 5px #00ffff;
            letter-spacing: 2px;
        }
        
        .theme-controls {
            margin-top: 30px;
            display: flex;
            justify-content: center;
            gap: 15px;
        }
        
        .theme-btn {
            background: rgba(0, 0, 0, 0.5);
            border: 2px solid #00ffff;
            color: #00ffff;
            padding: 10px 20px;
            border-radius: 30px;
            font-family: 'Orbitron', sans-serif;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.3s ease;
            outline: none;
        }
        
        .theme-btn:hover {
            background: rgba(0, 200, 255, 0.2);
            box-shadow: 0 0 15px #00ffff;
        }
        
        .footer {
            position: absolute;
            bottom: 20px;
            width: 100%;
            text-align: center;
            font-size: 0.9rem;
            color: rgba(255, 255, 255, 0.7);
        }
        
        /* 响应式设计 */
        @media (max-width: 900px) {
            .digit {
                width: 70px;
                height: 126px;
            }
            
            .segment {
                border-radius: 3px;
            }
            
            .segment-a, .segment-d, .segment-g { height: 10px; }
            .segment-b, .segment-c, .segment-e, .segment-f { width: 10px; }
            
            .colon {
                height: 126px;
                gap: 35px;
            }
            
            .dot {
                width: 15px;
                height: 15px;
            }
            
            h1 {
                font-size: 2rem;
            }
            
            .date-display {
                font-size: 1.4rem;
            }
        }
        
        @media (max-width: 600px) {
            .digit {
                width: 45px;
                height: 81px;
            }
            
            .segment-a, .segment-d, .segment-g { height: 7px; }
            .segment-b, .segment-c, .segment-e, .segment-f { width: 7px; }
            
            .colon {
                height: 81px;
                gap: 22px;
            }
            
            .dot {
                width: 10px;
                height: 10px;
            }
            
            h1 {
                font-size: 1.5rem;
            }
            
            .date-display {
                font-size: 1.1rem;
            }
            
            .container {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="particles" id="particles"></div>
    
    <div class="container">
        <h1>酷炫LED数字时钟</h1>
        
        <div class="clock-container">
            <!-- 小时 -->
            <div class="digit-group" id="hours">
                <div class="digit">
                    <div class="segment segment-a"></div>
                    <div class="segment segment-b"></div>
                    <div class="segment segment-c"></div>
                    <div class="segment segment-d"></div>
                    <div class="segment segment-e"></div>
                    <div class="segment segment-f"></div>
                    <div class="segment segment-g"></div>
                </div>
                <div class="digit">
                    <div class="segment segment-a"></div>
                    <div class="segment segment-b"></div>
                    <div class="segment segment-c"></div>
                    <div class="segment segment-d"></div>
                    <div class="segment segment-e"></div>
                    <div class="segment segment-f"></div>
                    <div class="segment segment-g"></div>
                </div>
            </div>
            
            <!-- 冒号 -->
            <div class="colon">
                <div class="dot active"></div>
                <div class="dot active"></div>
            </div>
            
            <!-- 分钟 -->
            <div class="digit-group" id="minutes">
                <div class="digit">
                    <div class="segment segment-a"></div>
                    <div class="segment segment-b"></div>
                    <div class="segment segment-c"></div>
                    <div class="segment segment-d"></div>
                    <div class="segment segment-e"></div>
                    <div class="segment segment-f"></div>
                    <div class="segment segment-g"></div>
                </div>
                <div class="digit">
                    <div class="segment segment-a"></div>
                    <div class="segment segment-b"></div>
                    <div class="segment segment-c"></div>
                    <div class="segment segment-d"></div>
                    <div class="segment segment-e"></div>
                    <div class="segment segment-f"></div>
                    <div class="segment segment-g"></div>
                </div>
            </div>
            
            <!-- 冒号 -->
            <div class="colon">
                <div class="dot active"></div>
                <div class="dot active"></div>
            </div>
            
            <!-- 秒 -->
            <div class="digit-group" id="seconds">
                <div class="digit">
                    <div class="segment segment-a"></div>
                    <div class="segment segment-b"></div>
                    <div class="segment segment-c"></div>
                    <div class="segment segment-d"></div>
                    <div class="segment segment-e"></div>
                    <div class="segment segment-f"></div>
                    <div class="segment segment-g"></div>
                </div>
                <div class="digit">
                    <div class="segment segment-a"></div>
                    <div class="segment segment-b"></div>
                    <div class="segment segment-c"></div>
                    <div class="segment segment-d"></div>
                    <div class="segment segment-e"></div>
                    <div class="segment segment-f"></div>
                    <div class="segment segment-g"></div>
                </div>
            </div>
        </div>
        
        <div class="date-display" id="dateDisplay"></div>
        
        <div class="theme-controls">
            <button class="theme-btn" id="blueTheme">蓝色主题</button>
            <button class="theme-btn" id="redTheme">红色主题</button>
            <button class="theme-btn" id="greenTheme">绿色主题</button>
        </div>
    </div>
    

    <script>
        // 数字段映射 (a, b, c, d, e, f, g)
        const digitMap = {
            0: [1, 1, 1, 1, 1, 1, 0],
            1: [0, 1, 1, 0, 0, 0, 0],
            2: [1, 1, 0, 1, 1, 0, 1],
            3: [1, 1, 1, 1, 0, 0, 1],
            4: [0, 1, 1, 0, 0, 1, 1],
            5: [1, 0, 1, 1, 0, 1, 1],
            6: [1, 0, 1, 1, 1, 1, 1],
            7: [1, 1, 1, 0, 0, 0, 0],
            8: [1, 1, 1, 1, 1, 1, 1],
            9: [1, 1, 1, 1, 0, 1, 1]
        };
        
        // 创建背景粒子
        function createParticles() {
            const particlesContainer = document.getElementById('particles');
            const particleCount = 50;
            
            for (let i = 0; i < particleCount; i++) {
                const particle = document.createElement('div');
                particle.classList.add('particle');
                
                // 随机大小
                const size = Math.random() * 10 + 2;
                particle.style.width = `${size}px`;
                particle.style.height = `${size}px`;
                
                // 随机位置
                particle.style.left = `${Math.random() * 100}%`;
                particle.style.top = `${Math.random() * 100}%`;
                
                // 随机动画延迟
                particle.style.animationDelay = `${Math.random() * 15}s`;
                
                particlesContainer.appendChild(particle);
            }
        }
        
        // 更新时间显示
        function updateTime() {
            const now = new Date();
            const hours = now.getHours().toString().padStart(2, '0');
            const minutes = now.getMinutes().toString().padStart(2, '0');
            const seconds = now.getSeconds().toString().padStart(2, '0');
            
            // 更新小时
            updateDigitGroup('hours', hours);
            // 更新分钟
            updateDigitGroup('minutes', minutes);
            // 更新秒
            updateDigitGroup('seconds', seconds);
            
            // 更新日期
            const dateDisplay = document.getElementById('dateDisplay');
            const options = { year: 'numeric', month: 'long', day: 'numeric', weekday: 'long' };
            dateDisplay.textContent = now.toLocaleDateString('zh-CN', options);
        }
        
        // 更新数字组
        function updateDigitGroup(groupId, digits) {
            const group = document.getElementById(groupId);
            const digitElements = group.querySelectorAll('.digit');
            
            for (let i = 0; i < digitElements.length; i++) {
                const digit = parseInt(digits[i]);
                const segments = digitElements[i].querySelectorAll('.segment');
                const segmentStates = digitMap[digit];
                
                for (let j = 0; j < segments.length; j++) {
                    if (segmentStates[j] === 1) {
                        segments[j].classList.add('active');
                    } else {
                        segments[j].classList.remove('active');
                    }
                }
            }
        }
        
        // 设置主题
        function setTheme(color) {
            const activeSegments = document.querySelectorAll('.segment.active, .dot.active');
            const buttons = document.querySelectorAll('.theme-btn');
            const containerGlow = document.querySelector('.container');
            
            // 移除所有颜色类
            activeSegments.forEach(segment => {
                segment.classList.remove('blue-theme', 'red-theme', 'green-theme');
            });
            
            buttons.forEach(button => {
                button.classList.remove('active-theme');
            });
            
            // 添加新颜色类
            activeSegments.forEach(segment => {
                segment.classList.add(`${color}-theme`);
            });
            
            // 更新容器发光效果
            containerGlow.style.boxShadow = `0 0 40px ${getThemeColor(color)}`;
            
            // 激活当前主题按钮
            document.getElementById(`${color}Theme`).classList.add('active-theme');
        }
        
        // 获取主题颜色
        function getThemeColor(theme) {
            switch(theme) {
                case 'blue': return 'rgba(0, 200, 255, 0.7)';
                case 'red': return 'rgba(255, 50, 50, 0.7)';
                case 'green': return 'rgba(50, 255, 50, 0.7)';
                default: return 'rgba(0, 200, 255, 0.7)';
            }
        }
        
        // 初始化
        document.addEventListener('DOMContentLoaded', () => {
            createParticles();
            updateTime();
            setInterval(updateTime, 1000);
            
            // 主题按钮事件
            document.getElementById('blueTheme').addEventListener('click', () => setTheme('blue'));
            document.getElementById('redTheme').addEventListener('click', () => setTheme('red'));
            document.getElementById('greenTheme').addEventListener('click', () => setTheme('green'));
            
            // 初始为蓝色主题
            setTheme('blue');
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值