Mesin capit pasar malam berisi ondel-ondel, kancil, dan durian dari SVG, dengan capit yang digerakkan requestAnimationFrame dan async/await. Seluruh mesin…
Oleh @belajarweb · JavaScript
<!doctype html>
<html lang="id">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Mesin Capit Hadiah</title>
<style>
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
min-height: 100vh;
background: radial-gradient(ellipse 70% 50% at 50% 105%, rgba(255,92,147,.28), rgba(255,92,147,0) 70%), linear-gradient(#150923, #261038 55%, #3a1650);
color: #fff4dc;
font-family: "Arial Rounded MT Bold", ui-rounded, "SF Pro Rounded", "Nunito", "Trebuchet MS", system-ui, sans-serif;
overflow-x: hidden;
-webkit-tap-highlight-color: transparent;
}
/* latar pasar malam */
.pasar { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.pasar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 7vh; background: #14081f; }
.lampu-tali, .bohlam-baris { position: absolute; left: 0; top: 0; width: 100%; height: 90px; }
.bohlam-baris i { position: absolute; width: 11px; height: 14px; margin: -2px 0 0 -5.5px; border-radius: 45% 45% 50% 50%; background: #ffe7a0; box-shadow: 0 0 10px 3px rgba(255,214,120,.55); }
.bohlam-baris i:nth-child(3n+1) { background: #ff9cc2; box-shadow: 0 0 10px 3px rgba(255,120,170,.5); }
.bohlam-baris i:nth-child(3n+2) { background: #8ff3e9; box-shadow: 0 0 10px 3px rgba(80,230,215,.45); }
.bohlam-baris i:nth-child(2n), .roda-lampu circle:nth-child(2n) { animation: kerlip 1.6s steps(2, jump-none) infinite; }
@keyframes kerlip { 50% { opacity: .35; } }
.bianglala { position: absolute; left: -3%; bottom: 4vh; height: 74vh; opacity: .8; }
.roda { transform-box: view-box; transform-origin: 100px 104px; animation: putar 48s linear infinite; }
@keyframes putar { to { transform: rotate(360deg); } }
.panggung { position: relative; min-height: 100vh; display: flex; align-items: center; justify-content: center; gap: clamp(20px, 5vw, 56px); padding: 16px; }
/* mesin: semua ukuran di dalamnya memakai cqw, jadi mesin bisa diskalakan utuh */
.mesin {
--mw: min(380px, 88vw, calc((100vh - 30px) / 1.72));
position: relative; isolation: isolate; flex: none;
width: var(--mw);
container-type: inline-size;
filter: drop-shadow(0 18px 26px rgba(0,0,0,.5));
}
.mesin::before { content: ""; position: absolute; left: 0; right: 0; top: 18cqw; bottom: 0; z-index: -1; border-radius: 3cqw; background: linear-gradient(90deg, #c92f68, #ff5c93 10%, #ff77a6 50%, #ff5c93 90%, #c92f68); }
.atap {
position: relative; height: 24cqw;
border: 1.4cqw solid #fff4dc;
border-radius: 46cqw 46cqw 3cqw 3cqw / 18cqw 18cqw 3cqw 3cqw;
background: linear-gradient(#45e6d6, #1aa99c);
}
.atap-lampu { position: absolute; inset: 1.2cqw; border-radius: inherit; border: 2cqw dotted #ffd34a; }
.atap-lampu-b { border-color: #fffbe6; animation: kerlip 1.1s steps(2, jump-none) infinite; }
.atap-papan {
position: absolute; left: 50%; top: 54%;
transform: translate(-50%, -50%) rotate(-2deg);
padding: .5cqw 5cqw 1.2cqw;
background: #fff4dc; border-radius: 3cqw; box-shadow: 0 1.2cqw 0 #c92f68;
text-align: center; line-height: .9;
}
.atap-papan b { display: block; font-size: 10.5cqw; font-weight: 900; letter-spacing: .04em; color: #ff3d7f; text-shadow: .5cqw .5cqw 0 #2b1630; }
.atap-papan small { display: block; margin-top: .4cqw; font-size: 3.6cqw; font-weight: 800; letter-spacing: .36em; text-transform: uppercase; color: #13867b; }
.kaca { position: relative; overflow: hidden; height: 92cqw; margin: 2cqw 4cqw 0; border: 1.4cqw solid #fff4dc; border-radius: 2.4cqw; background: #efe1ff; }
.kaca-dinding {
position: absolute; inset: 0;
background:
radial-gradient(circle at 25% 25%, #e1c7fb 0 7%, rgba(0,0,0,0) 7.5%) 0 0 / 11cqw 11cqw,
radial-gradient(circle at 75% 75%, #e1c7fb 0 7%, rgba(0,0,0,0) 7.5%) 0 0 / 11cqw 11cqw,
linear-gradient(#f7eeff, #e5d2ff 80%);
}
.kaca-lantai { position: absolute; left: 0; right: 0; bottom: 0; height: 5cqw; background: linear-gradient(#ffb3cd, #ff8db5); box-shadow: 0 -.6cqw 0 #ffd0e0; }
.lubang { position: absolute; left: 0; bottom: 0; z-index: 3; width: 21cqw; height: 28cqw; background: linear-gradient(rgba(255,255,255,.6), rgba(255,255,255,.3)); border: .9cqw solid #fff; border-width: .9cqw .9cqw 0 0; border-radius: 0 1.6cqw 0 0; }
.lubang::before { content: ""; position: absolute; left: 1cqw; right: 1cqw; top: -2.4cqw; height: 4cqw; border-radius: 50%; background: radial-gradient(ellipse, #3b1d4f 30%, #5c2e78 70%); border: .7cqw solid #fff; }
.lubang span { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) rotate(-8deg); padding: .6cqw 1.6cqw; border-radius: 1.2cqw; background: #ff3d7f; color: #fff; font-size: 3.2cqw; font-weight: 900; letter-spacing: .08em; }
#tumpuk { position: absolute; inset: 0; z-index: 2; }
.hadiah { position: absolute; width: 21cqw; height: 21cqw; transform-origin: 50% 85%; }
.hadiah svg { display: block; width: 100%; height: 100%; overflow: visible; }
.rel { position: absolute; left: 0; right: 0; top: 2.6cqw; z-index: 4; height: 2cqw; background: linear-gradient(#f0f2f8, #8b93a6); }
.kereta { position: absolute; top: 1.4cqw; left: 46cqw; z-index: 5; width: 0; }
.kereta-badan { position: absolute; left: -6.5cqw; top: 0; width: 13cqw; height: 5cqw; border-radius: 1.4cqw; background: linear-gradient(#5b5476, #2f2a45); }
.kereta-badan::before, .kereta-badan::after { content: ""; position: absolute; top: -1cqw; left: 1.4cqw; width: 3cqw; height: 3cqw; border-radius: 50%; background: #d9dde8; border: .6cqw solid #2f2a45; }
.kereta-badan::after { left: auto; right: 1.4cqw; }
.ayun { position: absolute; left: 0; top: 4.4cqw; transform-origin: 0 0; }
.tali { position: absolute; left: -.45cqw; top: 0; width: .9cqw; height: 3cqw; background: linear-gradient(90deg, #5d6478, #eef0f6, #5d6478); }
.capit { position: absolute; left: -10cqw; top: 3cqw; width: 20cqw; height: 18cqw; overflow: visible; }
.kilap {
position: absolute; inset: 0; z-index: 6; pointer-events: none;
background: linear-gradient(112deg, rgba(255,255,
…