找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 文档 工具 设计
查看: 35|回复: 0

写个简单的html5用餐座次图生成器

[复制链接]

2万

主题

1249

回帖

2万

积分

超级版主

教育辅助界扛把子

附加身份标识
精华
1
热心
7
听众
1
威望
48
贡献
14307
违规
0
书币
49981
注册时间
2020-4-8

论坛元老灌水之王

发表于 2024-6-30 14:28 | 显示全部楼层 |阅读模式
写个简单的html5用餐座次图生成器

[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用餐座次图</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            font-family: Arial, sans-serif;
        }
        #input-form {
            margin-bottom: 20px;
            text-align: center;
        }
        #form-elements {
            display: flex;
            align-items: center;
            gap: 10px; /* 增加间距 */
        }
        #form-elements input,
        #form-elements button {
            padding: 4px;
            font-weight: bold;
            border: 1px solid #88c416;
            color: #88c416;
        }
        #form-elements input {
            height: 20px; /* 统一高度 */
                        color: #88c416;
        }
        #form-elements button {
            cursor: pointer;
            height: 30px; /* 统一高度 */
        }
        #seating {
            position: relative;
            width: 500px;
            height: 500px;
            border-radius: 50%;
            background-color: #3399FF;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            text-align: center;
            font-weight: bold;
        }
        .seat {
            position: absolute;
            width: 60px;
            height: 30px;
            background: white;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 1px solid #88c416;
            border-radius: 10px;
            cursor: pointer;
        }
        .seat input {
            border: none;
            background: transparent;
            width: 100%;
            text-align: center;
        }
        [url=home.php?mod=space&uid=945662]@media[/url] print {
            #input-form, button , label {
                display: none;
            }
        }
    </style>
</head>
<body>
    <form id="input-form">
        <label for="table-info" style="color:#66CC00; height:25px; line-height:25px; font-weight:bold; padding:10px;">用餐座次图生成 (可拖动人员互换位置)</label><br><br>
        <div id="form-elements">
            <input type="text" id="table-info" required placeholder="桌号信息">
            <input type="text" id="names" required placeholder="张三、李四、王二">
            <button type="submit">生成座次</button>
        </div>
    </form>
    <div id="seating">
        <div id="table-info-display"></div>
    </div>
    <br><label style="color:#CCCCCC; height:25px; line-height:25px; padding:10px; font-size:10px;">&#169; RainMan</label>
    <script>
        document.getElementById('input-form').addEventListener('submit', function(event) {
            event.preventDefault();
            const tableInfo = document.getElementById('table-info').value;
            const names = document.getElementById('names').value.split(/[,,、]/).map(name => name.trim());
            document.getElementById('table-info-display').textContent = `${tableInfo} (${names.length}人)`;
            generateSeating(names);
        });
 
        function generateSeating(names) {
            const seating = document.getElementById('seating');
            const existingSeats = seating.querySelectorAll('.seat');
            existingSeats.forEach(seat => seat.remove());
 
            const numPeople = names.length;
            const angleStep = (2 * Math.PI) / numPeople;
            for (let i = 0; i < numPeople; i++) {
                const angle = i * angleStep - (Math.PI / 2);
                const x = 250 + 200 * Math.cos(angle);
                const y = 250 + 200 * Math.sin(angle);
                const seat = document.createElement('div');
                seat.classList.add('seat');
                seat.style.left = `${x - 30}px`;
                seat.style.top = `${y - 15}px`;
                seat.setAttribute('draggable', 'true');
                seat.addEventListener('dragstart', dragStart);
                seat.addEventListener('dragover', dragOver);
                seat.addEventListener('drop', drop);
                seat.addEventListener('dragend', dragEnd);
 
                const input = document.createElement('input');
                input.type = 'text';
                input.value = names[i];
                input.addEventListener('input', updateNamesList);
                seat.appendChild(input);
 
                seating.appendChild(seat);
            }
        }
 
        function updateNamesList() {
            const seats = document.querySelectorAll('.seat input');
            const names = Array.from(seats).map(input => input.value.trim()).filter(name => name !== '');
            document.getElementById('names').value = names.join('、');
            const tableInfo = document.getElementById('table-info').value;
            document.getElementById('table-info-display').textContent = `${tableInfo} (${names.length}人)`;
        }
 
        let draggedInput;
 
        function dragStart(event) {
            draggedInput = event.target.querySelector('input');
            event.dataTransfer.effectAllowed = 'move';
        }
 
        function dragOver(event) {
            event.preventDefault();
        }
 
        function drop(event) {
            event.preventDefault();
            const targetInput = event.target.closest('.seat').querySelector('input');
            if (targetInput && targetInput !== draggedInput) {
                const tempValue = draggedInput.value;
                draggedInput.value = targetInput.value;
                targetInput.value = tempValue;
                updateNamesList();
            }
        }
 
        function dragEnd() {
            draggedInput = null;
        }
    </script>
</body>
</html>


Great works are not done by strength, but by persistence! 历尽艰辛的飞升者,成了围剿孙悟空的十万天兵之一。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号


免责声明:
本站所发布的第三方软件及资源(包括但不仅限于文字/图片/音频/视频等仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢某程序或某个资源,请支持正版软件及版权方利益,注册或购买,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To: admin@cdsy.xyz

QQ|Archiver|手机版|小黑屋|城东书院 ( 湘ICP备19021508号-1|湘公网安备 43102202000103号 )

GMT+8, 2024-11-21 16:54 , Processed in 0.053939 second(s), 27 queries .

Powered by Discuz! CDSY.XYZ

Copyright © 2019-2023, Tencent Cloud.

快速回复 返回顶部 返回列表