返回模板

Interactive study flashcards

A keyboard-friendly single-file flashcard deck with flip animations and progress tracking.

用这个模板

完整源码

1 行 · 1.9 KB
<style>*{box-sizing:border-box}body{margin:0;font-family:Inter,system-ui,sans-serif;background:#f6f7fb;color:#172033}button,a{font:inherit}.wrap{width:min(960px,calc(100% - 32px));margin:auto}</style><style>main{min-height:100vh;display:grid;place-items:center;padding:24px}.deck{width:min(480px,100%);text-align:center}.card{background:#fff;border:1px solid #dfe3ec;border-radius:20px;padding:36px 28px;min-height:220px;display:grid;place-items:center;cursor:pointer;box-shadow:0 16px 40px #1e293b10}.q{font-size:22px;font-weight:700}.a{font-size:17px;color:#0f766e;line-height:1.6}.controls{display:flex;justify-content:space-between;align-items:center;margin-top:16px}.controls button{padding:10px 18px;border-radius:10px;border:1px solid #cfd5e2;background:#fff;cursor:pointer;font-weight:600}</style><main><div class="deck"><p id="prog">Card 1 of 3</p><div class="card" tabindex="0" onclick="flip()" onkeydown="if(event.key==='Enter'||event.key===' ')flip()"><div id="face" class="q"></div></div><div class="controls"><button onclick="step(-1)">Prev</button><button onclick="flip()">Flip</button><button onclick="step(1)">Next</button></div></div></main><script>const cards=[{q:"What does CSS clamp(min, pref, max) do?",a:"It keeps a value responsive between a minimum and maximum bound without media queries."},{q:"Why omit allow-same-origin on untrusted iframes?",a:"It assigns an opaque origin so scripts cannot access parent cookies or storage."},{q:"What makes a single-file demo easy to review?",a:"Self-contained HTML/CSS/JS with deterministic sample data."}];let i=0,shown=false;function render(){const f=document.getElementById("face");f.className=shown?"a":"q";f.textContent=shown?cards[i].a:cards[i].q;document.getElementById("prog").textContent="Card "+(i+1)+" of "+cards.length}function flip(){shown=!shown;render()}function step(d){i=(i+d+cards.length)%cards.length;shown=false;render()}render()</script>

适用场景

适合单词记忆、考前复习、面试刷题和课堂提问等需要主动回忆的场景,无需安装客户端即可直接使用。

布局原理

居中卡片在正面题目与背面答案之间切换,配有进度计数与上一张/翻面/下一张按钮,同时支持 Enter 和空格键翻卡。

如何定制

直接修改脚本中的 cards 数组即可替换成你自己的题库,也可以按章节增加标签或调整长答案字号。

发布前检查

检查键盘焦点顺序、390px 手机端换行效果,并尽量让每张卡片控制在无需滚动的一屏内读完。

带着上下文继续制作

在编辑器中改编示例之前,可以先比较相关模式或阅读实用指南。