代码 一个数字时钟的HTML

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

该文本展示了一个数字时钟的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中处理全局状态管理?
2024-11-18 19:25:59 +0800 CST
介绍Vue3的Tree Shaking是什么?
2024-11-18 20:37:41 +0800 CST
go错误处理
2024-11-18 18:17:38 +0800 CST
使用Python提取图片中的GPS信息
2024-11-18 13:46:22 +0800 CST
使用 Nginx 获取客户端真实 IP
2024-11-18 14:51:58 +0800 CST
windows安装sphinx3.0.3(中文检索)
2024-11-17 05:23:31 +0800 CST
黑客帝国代码雨效果
2024-11-19 01:49:31 +0800 CST
gin整合go-assets进行打包模版文件
2024-11-18 09:48:51 +0800 CST
html一些比较人使用的技巧和代码
2024-11-17 05:05:01 +0800 CST
动态渐变背景
2024-11-19 01:49:50 +0800 CST
nginx反向代理
2024-11-18 20:44:14 +0800 CST
Nginx 反向代理 Redis 服务
2024-11-19 09:41:21 +0800 CST
使用Python实现邮件自动化
2024-11-18 20:18:14 +0800 CST
rangeSlider进度条滑块
2024-11-19 06:49:50 +0800 CST
一些好玩且实用的开源AI工具
2024-11-19 09:31:57 +0800 CST
windows下mysql使用source导入数据
2024-11-17 05:03:50 +0800 CST
LangChain快速上手
2025-03-09 22:30:10 +0800 CST
任务管理工具的HTML
2025-01-20 22:36:11 +0800 CST
Vue3中的Slots有哪些变化?
2024-11-18 16:34:49 +0800 CST
如何在 Vue 3 中使用 TypeScript?
2024-11-18 22:30:18 +0800 CST
Golang Select 的使用及基本实现
2024-11-18 13:48:21 +0800 CST
php strpos查找字符串性能对比
2024-11-19 08:15:16 +0800 CST
程序员出海搞钱工具库
2024-11-18 22:16:19 +0800 CST
pin.gl是基于WebRTC的屏幕共享工具
2024-11-19 06:38:05 +0800 CST
程序员茄子在线接单