新奇验证码之读数闹钟 ,6

bash 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Clock CAPTCHA with Whole and Half Hours</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        .container {
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
            text-align: center;
        }
        .clock {
            width: 200px;
            height: 200px;
            border: 2px solid black;
            border-radius: 50%;
            position: relative;
            margin: 20px auto;
        }
        .hand {
            background: black;
            position: absolute;
            transform-origin: bottom center;
        }
        .hour {
            width: 6px;
            height: 60px;
            top: 40px;
            left: 97px;
        }
        .minute {
            width: 4px;
            height: 80px;
            top: 20px;
            left: 98px;
        }
        .number {
            position: absolute;
            font-size: 18px;
            font-weight: bold;
        }
        input, button {
            margin: 10px 0;
            padding: 5px;
        }
        #message {
            margin-top: 10px;
            font-weight: bold;
        }
    </style>
</head>
<body>
<div class="container">
    <h2>时钟验证码</h2>
    <div class="clock" id="clock">
        <div class="hand hour" id="hourHand"></div>
        <div class="hand minute" id="minuteHand"></div>
        <!-- Clock numbers will be added here by JavaScript -->
    </div>
    <input type="text" id="timeInput" placeholder="请输入时间 (HH:MM)">
    <button onclick="checkTime()">确定</button>
    <button onclick="generateRandomTime()">换验证码</button>
    <div id="message"></div>
</div>

<script>
    let currentTime = { hours: 0, minutes: 0 };

    function setClockHands(hours, minutes) {
        const hourHand = document.getElementById('hourHand');
        const minuteHand = document.getElementById('minuteHand');
        const hourDegrees = (hours % 12 + minutes / 60) * 30;
        const minuteDegrees = minutes * 6;

        hourHand.style.transform = `rotate(${hourDegrees}deg)`;
        minuteHand.style.transform = `rotate(${minuteDegrees}deg)`;
    }

    function addClockNumbers() {
        const clock = document.getElementById('clock');
        for (let i = 1; i <= 12; i++) {
            const number = document.createElement('div');
            number.className = 'number';
            number.textContent = i;
            const angle = (i - 3) * 30 * (Math.PI / 180);
            const x = 90 + 80 * Math.cos(angle);
            const y = 90 + 80 * Math.sin(angle);
            number.style.left = `${x}px`;
            number.style.top = `${y}px`;
            clock.appendChild(number);
        }
    }

    function generateRandomTime() {
        const hours = Math.floor(Math.random() * 12) + 1; // 1 to 12
        const minutes = Math.random() < 0.5 ? 0 : 30; // Only 0 or 30 minutes
        currentTime = { hours, minutes };
        setClockHands(hours, minutes);
        document.getElementById('timeInput').value = '';
        document.getElementById('message').textContent = '';
    }

    function checkTime() {
        const input = document.getElementById('timeInput').value;
        const [inputHours, inputMinutes] = input.split(':').map(Number);
        const correctTime = `${String(currentTime.hours).padStart(2, '0')}:${String(currentTime.minutes).padStart(2, '0')}`;

        if (inputHours === currentTime.hours && inputMinutes === currentTime.minutes) {
            document.getElementById('message').textContent = '验证通过!';
            document.getElementById('message').style.color = 'green';
        } else {
            document.getElementById('message').textContent = '时间不正确,请重试。';
            document.getElementById('message').style.color = 'red';
        }
    }

    // 初始化时钟
    addClockNumbers();
    generateRandomTime();
</script>
</body>
</html>
相关推荐
@解忧杂货铺1 小时前
前端vue如何实现数字框中通过鼠标滚轮上下滚动增减数字
前端·javascript·vue.js
WebDeveloper20013 小时前
如何使用美国域名中心US Domain Center和WordPress创建商业网站
运维·服务器·css·网络·html
真的很上进6 小时前
如何借助 Babel+TS+ESLint 构建现代 JS 工程环境?
java·前端·javascript·css·react.js·vue·html
噢,我明白了10 小时前
同源策略:为什么XMLHttpRequest不能跨域请求资源?
javascript·跨域
sanguine__10 小时前
APIs-day2
javascript·css·css3
关你西红柿子10 小时前
小程序app封装公用顶部筛选区uv-drop-down
前端·javascript·vue.js·小程序·uv
济南小草根10 小时前
把一个Vue项目的页面打包后再另一个项目中使用
前端·javascript·vue.js
小木_.11 小时前
【python 逆向分析某有道翻译】分析有道翻译公开的密文内容,webpack类型,全程扣代码,最后实现接口调用翻译,仅供学习参考
javascript·python·学习·webpack·分享·逆向分析
LUwantAC11 小时前
CSS(一):选择器
前端·css
Aphasia31111 小时前
一次搞懂 JS 对象转换,从此告别类型错误!
javascript·面试