代码 一个数字时钟的HTML

2024-11-19 07:46:53 +0800 CST views 947

该文本展示了一个数字时钟的HTML实现,使用CSS进行样式设计和动画效果,JavaScript用于实时更新时钟。时钟显示12小时制时间,并具有渐变背景和动态色彩变化的效果,整体设计简洁且现代。
images

<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数字时钟</title>
    <style>
        :root {
            --color2: #56d5fc;
            --color4: #def700;
            --color6: #fa3195;
        }

        * {
            margin: 0;
            padding: 0;
        }

        html {
            font-size: 14px;
        }

        body {
            width: 100vw;
            height: 100vh;
            background-color: #000;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'Montserrat', sans-serif, Arial, 'Microsoft Yahei';
        }

        .clock_box {
            position: relative;
            width: 380px;
            height: 80px;
            border-radius: 10px;
            background-image: linear-gradient(135deg, var(--color2), var(--color4), var(--color6));
            display: flex;
            justify-content: center;
            align-items: center;
            animation: animate 4s linear infinite;
        }

        .clock_box::after, .clock_box::before {
            position: absolute;
            content: "";
            background-image: inherit;
            width: 100%;
            height: 100%;
            z-index: -1;
            border-radius: 10px;
            filter: blur(15px);
        }

        .clock_box::before {
            filter: blur(100px);
        }

        .clock {
            position: absolute;
            left: 10px;
            right: 10px;
            top: 10px;
            bottom: 10px;
            background-color: #2b2a2a;
            border-radius: 8px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .clock p {
            font-size: 50px;
            font-weight: bold;
            color: transparent;
            letter-spacing: 2px;
            background-image: linear-gradient(135deg, var(--color2), var(--color4), var(--color6));
            background-clip: text;
            -webkit-background-clip: text;
        }

        @keyframes animate {
            100% {
                filter: hue-rotate(360deg);
            }
        }
    </style>
</head>
<body>
    <div class="clock_box">
        <div class="clock">
            <p id="time"></p>
        </div>
    </div>
    <script>
        var time = document.querySelector("#time");

        function up(time_el) {
            let date = new Date();
            let h = date.getHours();
            let m = date.getMinutes();
            let s = date.getSeconds();
            let day_night = "AM";

            if (h > 12) {
                h = h - 12;
                day_night = "PM";
            }

            if (h < 10) { h = "0" + h; }
            if (m < 10) { m = "0" + m; }
            if (s < 10) { s = "0" + s; }

            time_el.textContent = h + ":" + m + ":" + s + " " + day_night;
        }

        setInterval(() => {
            up(time);
        }, 1000);
    </script>
</body>
</html>

复制全文 生成海报 前端开发 网页设计 编程

推荐文章

Vue3中如何处理WebSocket通信?
2024-11-19 09:50:58 +0800 CST
PHP服务器直传阿里云OSS
2024-11-18 19:04:44 +0800 CST
Vue3结合Driver.js实现新手指引功能
2024-11-19 08:46:50 +0800 CST
Vue 中如何处理跨组件通信?
2024-11-17 15:59:54 +0800 CST
Vue3中怎样处理组件引用?
2024-11-18 23:17:15 +0800 CST
JavaScript设计模式:单例模式
2024-11-18 10:57:41 +0800 CST
liunx服务器监控workerman进程守护
2024-11-18 13:28:44 +0800 CST
Nginx rewrite 的用法
2024-11-18 22:59:02 +0800 CST
thinkphp分页扩展
2024-11-18 10:18:09 +0800 CST
File 和 Blob 的区别
2024-11-18 23:11:46 +0800 CST
Roop是一款免费开源的AI换脸工具
2024-11-19 08:31:01 +0800 CST
Python Invoke:强大的自动化任务库
2024-11-18 14:05:40 +0800 CST
Python上下文管理器:with语句
2024-11-19 06:25:31 +0800 CST
Node.js中接入微信支付
2024-11-19 06:28:31 +0800 CST
Vue3 结合 Driver.js 实现新手指引
2024-11-18 19:30:14 +0800 CST
Nginx 防止IP伪造,绕过IP限制
2025-01-15 09:44:42 +0800 CST
Vue3中如何处理跨域请求?
2024-11-19 08:43:14 +0800 CST
程序员茄子在线接单