SnIPPETsX
SnIPPETsX

SnIPPETsX › { margin: 0; padding: 0; box-sizing: border-box; }

{ margin: 0; padding: 0; box-sizing: border-box; }

JavaScript · updated Nov 30, 2026 · 213 lines

main.js

<!DOCTYPE html>
<html lang="zh-Hant">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>塔羅占卜</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    background: #1a1423;
    font-family: Georgia, serif;
    color: #f0e6d3;
    min-height: 100vh;
    padding: 20px;
    display: flex;
    justify-content: center;
}
.app { max-width: 500px; width: 100%; }
h1 { text-align: center; color: #c9a96e; font-size: 1.8rem; margin-bottom: 10px; }
.question-box { margin-bottom: 20px; }
.question-box input {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #c9a96e;
    background: #2d2140;
    color: #f0e6d3;
    font-size: 1rem;
    outline: none;
}
.spread-selector { display: flex; gap: 10px; margin-bottom: 20px; }
.spread-selector button {
    flex: 1;
    padding: 10px;
    border-radius: 20px;
    border: 1px solid #c9a96e;
    background: transparent;
    color: #c9a96e;
    cursor: pointer;
    font-size: 0.85rem;
}
.spread-selector button.active {
    background: #7a5c9e;
    color: #fff;
    border-color: #7a5c9e;
}
.deck { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-bottom: 20px; }
.card {
    width: 80px;
    height: 120px;
    perspective: 1000px;
    cursor: pointer;
}
.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
}
.card.flipped .card-inner {
    transform: rotateY(180deg);
}
.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 8px;
    text-align: center;
}
.card-front {
    background: linear-gradient(135deg, #2d2140, #1a1423);
    border: 2px solid #c9a96e;
    color: #c9a96e;
    font-size: 2rem;
}
.card-back {
    background: linear-gradient(135deg, #c9a96e, #a0824a);
    color: #1a1423;
    transform: rotateY(180deg);
    border: 2px solid #fff;
    font-size: 0.75rem;
    font-weight: bold;
}
.result { margin-top: 20px; }
.result-item {
    background: #2d2140;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 12px;
    border-left: 4px solid #c9a96e;
}
.result-item h3 { color: #c9a96e; margin-bottom: 6px; font-size: 1rem; }
.result-item p { color: #cbbfa8; font-size: 0.85rem; line-height: 1.5; }
.reset-btn {
    width: 100%;
    padding: 14px;
    border-radius: 30px;
    border: none;
    background: #c9a96e;
    color: #1a1423;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    margin-top: 20px;
}
</style>
</head>
<body>
<div class="app">
    <h1>🔮 塔羅占卜</h1>
    <div class="question-box">
        <input type="text" id="question" placeholder="输入你的问题,比如:我最近感情会顺利吗?">
    </div>
    <div class="spread-selector">
        <button class="active" data-count="3">三张牌</button>
        <button data-count="10">凯尔特十字</button>
    </div>
    <div class="deck" id="deck"></div>
    <div class="result" id="result"></div>
    <button class="reset-btn" id="reset">重新抽牌</button>
</div>

<script>
const cards = [
    { name: '愚者', symbol: '🃏', up: '新的开始、冒险、无限可能', rev: '鲁莽、犹豫不决' },
    { name: '魔术师', symbol: '🎩', up: '创造力、意志力、显化', rev: '欺骗、缺乏行动' },
    { name: '女祭司', symbol: '🌙', up: '直觉、智慧、静观', rev: '忽略直觉、肤浅' },
    { name: '皇后', symbol: '👑', up: '丰盛、滋养、感官享受', rev: '依赖、匮乏感' },
    { name: '皇帝', symbol: '🏛️', up: '权威、结构、稳固', rev: '专制、僵化' },
    { name: '教皇', symbol: '📜', up: '传统、信仰、指导', rev: '挑战传统、盲从' },
    { name: '恋人', symbol: '💞', up: '爱情、选择、和谐', rev: '不和谐、错误选择' },
    { name: '战车', symbol: '🛡️', up: '胜利、决心、前进', rev: '失控、缺乏方向' },
    { name: '力量', symbol: '🦁', up: '勇气、耐心、内在力量', rev: '自我怀疑、恐惧' },
    { name: '隐者', symbol: '🏮', up: '内省、智慧、寻求真理', rev: '孤立、退缩' },
    { name: '命运之轮', symbol: '☸️', up: '转变、机遇、命运', rev: '停滞、抗拒改变' },
    { name: '正义', symbol: '⚖️', up: '公平、真相、因果', rev: '不公平、逃避责任' },
    { name: '倒吊人', symbol: '🙃', up: '牺牲、放手、静待', rev: '无谓牺牲、拖延' },
    { name: '死神', symbol: '💀', up: '结束、重生、放下', rev: '抗拒改变、无法放手' },
    { name: '节制', symbol: '⚗️', up: '平衡、调和、耐心', rev: '失衡、缺乏协调' },
    { name: '恶魔', symbol: '😈', up: '束缚、诱惑、阴影', rev: '觉醒、摆脱束缚' },
    { name: '高塔', symbol: '🗼', up: '剧变、觉醒、突破', rev: '恐惧改变、勉强维持' },
    { name: '星星', symbol: '🌟', up: '希望、灵感、疗愈', rev: '绝望、失去信心' },
    { name: '月亮', symbol: '🌕', up: '幻象、潜意识、不安', rev: '释放恐惧、真相浮现' },
    { name: '太阳', symbol: '☀️', up: '成功、喜悦、清晰', rev: '暂时阴霾、延迟' },
    { name: '审判', symbol: '📯', up: '重生、觉醒、宽恕', rev: '自我怀疑、悔恨' },
    { name: '世界', symbol: '🌍', up: '完成、成就、圆满', rev: '未完成、缺乏收尾' }
];

let selectedCount = 3;
let drawnCards = [];

document.querySelectorAll('.spread-selector button').forEach(btn => {
    btn.onclick = () => {
        document.querySelectorAll('.spread-selector button').forEach(b => b.classList.remove('active'));
        btn.classList.add('active');
        selectedCount = parseInt(btn.dataset.count);
        resetDeck();
    };
});

function resetDeck() {
    drawnCards = [];
    document.getElementById('result').innerHTML = '';
    const deck = document.getElementById('deck');
    deck.innerHTML = '';
    const shuffled = [...cards].sort(() => Math.random() - 0.5);
    shuffled.slice(0, selectedCount * 2).forEach((card, i) => {
        const div = document.createElement('div');
        div.className = 'card';
        div.innerHTML = `
            <div class="card-inner">
                <div class="card-front">🔮</div>
                <div class="card-back">${card.symbol}<br>${card.name}</div>
            </div>
        `;
        div.onclick = () => {
            if (div.classList.contains('flipped') || drawnCards.length >= selectedCount) return;
            div.classList.add('flipped');
            const reversed = Math.random() < 0.4;
            drawnCards.push({ ...card, reversed });
            setTimeout(() => showResult(), 600);
        };
        deck.appendChild(div);
    });
}

function showResult() {
    const question = document.getElementById('question').value || '(未输入问题)';
    let html = `<h3 style="color:#c9a96e;margin-bottom:12px;">问题:${question}</h3>`;
    drawnCards.forEach((c, i) => {
        html += `
            <div class="result-item">
                <h3>${c.symbol} ${c.name} ${c.reversed ? '(逆位)' : '(正位)'}</h3>
                <p><strong>位置 ${i + 1}:</strong>${c.reversed ? c.rev : c.up}</p>
            </div>
        `;
    });
    document.getElementById('result').innerHTML = html;
}

document.getElementById('reset').onclick = resetDeck;
resetDeck();
</script>
</body>
</html>

Run this JavaScript snippet

Open this snippet on SnIPPETsX to run the JavaScript code in your browser, edit it together with others in real time, or fork it into your own copy. No install or account is needed.