示例工程 35-keyframes
35-keyframes/demo-01-basic/style.css
点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。
:root {
--border: #e2e8f0;
--muted: #64748b;
--primary: #2563eb;
}
body {
margin: 0;
padding: 32px;
background: #f8fafc;
color: #0f172a;
font-family: system-ui, sans-serif;
line-height: 1.7;
}
h1 { margin: 0 0 8px; font-size: 26px; }
#pause { position: absolute; opacity: 0; width: 1px; height: 1px; }
label {
display: inline-flex;
margin-top: 8px;
padding: 6px 14px;
border: 1px solid var(--border);
border-radius: 999px;
background: #ffffff;
color: var(--muted);
font-size: 12px;
cursor: pointer;
}
#pause:checked + h1 + p + label {
border-color: var(--primary);
background: var(--primary);
color: #ffffff;
}
#pause:checked ~ .row .box { animation-play-state: paused; }
.row {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 16px;
max-width: 720px;
margin-top: 18px;
}
.cell {
display: grid;
justify-items: center;
gap: 8px;
padding: 16px 8px;
border: 1px solid var(--border);
border-radius: 10px;
background: #ffffff;
}
.cell span {
color: var(--muted);
font-size: 10px;
font-family: ui-monospace, monospace;
}
.box {
width: 40px;
height: 40px;
border-radius: 8px;
background: linear-gradient(135deg, #2563eb, #7c3aed);
}
.spin { border-radius: 50%; }
.pulse { animation: pulse 1.6s ease-in-out infinite; }
.bounce { animation: bounce 1.2s ease-in-out infinite; }
.spin { animation: spin 1.8s linear infinite; }
.shake { animation: shake 1.4s ease-in-out infinite; }
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.2); opacity: 0.6; }
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-14px); }
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-6px); }
75% { transform: translateX(6px); }
}
@media (max-width: 640px) {
.row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
.box { animation: none; }
.spin { border-radius: 50%; }
}