Treasure Chest
Click to shake a treasure chest that rattles, then bursts open with a shower of golden coins
Embed this component
Paste this snippet into any site — the design renders in a sandboxed iframe served from /embed/treasure-chest-button.
<iframe src="/embed/treasure-chest-button" sandbox="allow-scripts" loading="lazy" title="Treasure Chest" style="border:0;width:100%;height:480px;overflow:hidden"></iframe>Implementation code
Copy the HTML and CSS for Treasure Chest, or grab a framework-specific implementation. The HTML and CSS variants are self-contained; framework variants assume that framework's project setup.
HTML
<button class="btn-chest" id="chestBtn" onclick="triggerChest()">
<span class="chest-icon">🧰</span>
<span class="text">Claim Reward</span>
</button>
<script>
function triggerChest(){const btn=document.getElementById('chestBtn');if(btn.classList.contains('is-shaking'))return;btn.classList.add('is-shaking');btn.querySelector('.text').innerText='Unlocking...';setTimeout(()=>{btn.classList.remove('is-shaking');btn.classList.add('is-open');btn.querySelector('.chest-icon').innerText='🎁';btn.querySelector('.text').innerText='Claimed!';for(let i=0;i<12;i++){const c=document.createElement('div');c.innerText='🪙';c.classList.add('coin');c.style.setProperty('--tx',(Math.random()-0.5)*150+'px');c.style.setProperty('--ty',-40-Math.random()*80+'px');btn.appendChild(c);}},1200);setTimeout(()=>{btn.classList.remove('is-open');btn.querySelector('.chest-icon').innerText='🧰';btn.querySelector('.text').innerText='Claim Reward';btn.querySelectorAll('.coin').forEach(c=>c.remove());},4500);}
</script>CSS
.btn-chest{width:160px;height:50px;border-radius:12px;border:none;background:#b45309;color:#fff;font-size:16px;font-weight:700;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;overflow:visible;transition:all .4s cubic-bezier(.4,0,.2,1);box-shadow:0 4px 15px rgba(180,83,9,.4);font-family:system-ui,sans-serif}.btn-chest .chest-icon{font-size:20px;transition:.3s}.btn-chest.is-shaking{animation:chest-shake .2s infinite}.btn-chest.is-shaking .chest-icon{animation:chest-icon-shake .1s infinite}.btn-chest.is-open{background:#f59e0b;color:#000;box-shadow:0 0 25px rgba(245,158,11,.8)}.coin{position:absolute;font-size:16px;opacity:0;pointer-events:none}.is-open .coin{animation:coin-burst .8s forwards cubic-bezier(.2,.8,.2,1)}@keyframes chest-shake{0%,100%{transform:translateX(0) rotate(0)}50%{transform:translateX(-3px) rotate(-5deg)}}@keyframes chest-icon-shake{0%,100%{transform:translateX(0)}50%{transform:translateX(-3px)}}@keyframes coin-burst{0%{transform:translate(0,10px) scale(.5);opacity:1}100%{transform:translate(var(--tx),var(--ty)) scale(1.2);opacity:0}}Tailwind CSS
<button class="w-[160px] h-[50px] rounded-xl border-none bg-amber-700 text-white text-base font-bold cursor-pointer flex items-center justify-center gap-2 overflow-visible transition-all duration-400 shadow-[0_4px_15px_rgba(180,83,9,0.4)] [&.is-shaking]:animate-[chest-shake_0.2s_infinite] [&.is-open]:bg-amber-400 [&.is-open]:text-black [&.is-open]:shadow-[0_0_25px_rgba(245,158,11,0.8)]" id="tw-chest">
<span class="chest-icon text-xl">🧰</span>
<span class="text">Claim Reward</span>
</button>React
import React from 'react';
import { motion } from 'framer-motion';
function TreasureChestButton() {
const [state, setState] = React.useState('idle');
const handleClick = () => {
if (state !== 'idle') return;
setState('shaking');
setTimeout(() => setState('open'), 1200);
setTimeout(() => setState('idle'), 4500);
};
const sh = state === 'shaking';
const op = state === 'open';
const coins = op ? [...Array(12)].map(() => ({ tx: (Math.random()-0.5)*150, ty: -40-Math.random()*80, delay: Math.random()*0.5 })) : [];
return (
<motion.button onClick={handleClick}
style={{ width: 160, height: 50, borderRadius: 12, border: 'none', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 8, position: 'relative', fontSize: 16, fontWeight: 700, color: op ? '#000' : '#fff', background: op ? '#f59e0b' : '#b45309', boxShadow: op ? '0 0 25px rgba(245,158,11,0.8)' : '0 4px 15px rgba(180,83,9,0.4)', transition: 'all 0.4s cubic-bezier(0.4,0,0.2,1)', overflow: 'visible', fontFamily: 'system-ui, sans-serif' }}
animate={sh ? { x: [0,-3,3,-3,3,0], rotate: [0,-5,5,-5,5,0], transition: { duration: 0.2, repeat: Infinity } } : { x: 0, rotate: 0 }}
whileTap={state === 'idle' ? { scale: 0.95 } : {}} disabled={state !== 'idle'}>
<motion.span style={{ fontSize: 20 }} animate={sh ? { x: [0,-3,3,-3,3,0], transition: { duration: 0.1, repeat: Infinity } } : {}}>{op ? '🎁' : '🧰'}</motion.span>
<span>{op ? 'Claimed!' : sh ? 'Unlocking...' : 'Claim Reward'}</span>
{coins.map((c,i)=>(
<motion.span key={i} style={{ position: 'absolute', fontSize: 16, pointerEvents: 'none', opacity: 0 }}
initial={{ x: 0, y: 10, scale: 0.5, opacity: 1 }}
animate={{ x: c.tx, y: c.ty, scale: 1.2, opacity: 0 }}
transition={{ duration: 0.8, ease: [0.2,0.8,0.2,1], delay: c.delay }}>🪙</motion.span>
))}
</motion.button>
);
}Vue
<template>
<button class="btn-chest" :class="{'is-shaking':state==='shaking','is-open':state==='open'}" @click="handleClick" :disabled="state!=='idle'">
<span class="chest-icon">{{ state==='open' ? '🎁' : '🧰' }}</span>
<span class="text">{{ state==='open' ? 'Claimed!' : state==='shaking' ? 'Unlocking...' : 'Claim Reward' }}</span>
</button>
</template>
<script setup>
import { ref } from 'vue';
const state = ref('idle');
function handleClick() {
if (state.value !== 'idle') return;
state.value = 'shaking';
setTimeout(() => state.value = 'open', 1200);
setTimeout(() => state.value = 'idle', 4500);
}
</script>
<style scoped>
.btn-chest{width:160px;height:50px;border-radius:12px;border:none;background:#b45309;color:#fff;font-size:16px;font-weight:700;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;overflow:visible;transition:all .4s cubic-bezier(.4,0,.2,1);box-shadow:0 4px 15px rgba(180,83,9,.4)}.btn-chest .chest-icon{font-size:20px}.btn-chest.is-shaking{animation:chest-shake .2s infinite}.btn-chest.is-open{background:#f59e0b;color:#000;box-shadow:0 0 25px rgba(245,158,11,.8)}.coin{position:absolute;font-size:16px;opacity:0;pointer-events:none}.is-open .coin{animation:coin-burst .8s forwards cubic-bezier(.2,.8,.2,1)}@keyframes chest-shake{0%,100%{transform:translateX(0) rotate(0)}50%{transform:translateX(-3px) rotate(-5deg)}}@keyframes coin-burst{0%{transform:translate(0,10px) scale(.5);opacity:1}100%{transform:translate(var(--tx),var(--ty)) scale(1.2);opacity:0}}
</style>Svelte
<script>
let state = 'idle';
function handleClick() {
if (state !== 'idle') return;
state = 'shaking';
setTimeout(() => state = 'open', 1200);
setTimeout(() => state = 'idle', 4500);
}
</script>
<button class="btn-chest" class:is-shaking={state==='shaking'} class:is-open={state==='open'} on:click={handleClick} disabled={state!=='idle'}>
<span class="chest-icon">{state==='open' ? '🎁' : '🧰'}</span>
<span>{state==='open' ? 'Claimed!' : state==='shaking' ? 'Unlocking...' : 'Claim Reward'}</span>
</button>
<style>
.btn-chest{width:160px;height:50px;border-radius:12px;border:none;background:#b45309;color:#fff;font-size:16px;font-weight:700;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;overflow:visible;transition:all .4s cubic-bezier(.4,0,.2,1);box-shadow:0 4px 15px rgba(180,83,9,.4)}.btn-chest .chest-icon{font-size:20px}.btn-chest.is-shaking{animation:chest-shake .2s infinite}.btn-chest.is-open{background:#f59e0b;color:#000;box-shadow:0 0 25px rgba(245,158,11,.8)}.coin{position:absolute;font-size:16px;opacity:0;pointer-events:none}.is-open .coin{animation:coin-burst .8s forwards cubic-bezier(.2,.8,.2,1)}@keyframes chest-shake{0%,100%{transform:translateX(0) rotate(0)}50%{transform:translateX(-3px) rotate(-5deg)}}@keyframes coin-burst{0%{transform:translate(0,10px) scale(.5);opacity:1}100%{transform:translate(var(--tx),var(--ty)) scale(1.2);opacity:0}}
</style>Angular
import { Component } from '@angular/core';
@Component({
selector: 'app-treasure-chest-button',
template: `<button class="btn-chest" [class.is-shaking]="state==='shaking'" [class.is-open]="state==='open'" (click)="handleClick()" [disabled]="state!=='idle'">
<span class="chest-icon">{{ state==='open' ? '🎁' : '🧰' }}</span>
<span class="text">{{ state==='open' ? 'Claimed!' : state==='shaking' ? 'Unlocking...' : 'Claim Reward' }}</span>
</button>`,
styles: [`.btn-chest{width:160px;height:50px;border-radius:12px;border:none;background:#b45309;color:#fff;font-size:16px;font-weight:700;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;overflow:visible;transition:all .4s cubic-bezier(.4,0,.2,1);box-shadow:0 4px 15px rgba(180,83,9,.4)}.btn-chest .chest-icon{font-size:20px}.btn-chest.is-shaking{animation:chest-shake .2s infinite}.btn-chest.is-open{background:#f59e0b;color:#000;box-shadow:0 0 25px rgba(245,158,11,.8)}.coin{position:absolute;font-size:16px;opacity:0;pointer-events:none}.is-open .coin{animation:coin-burst .8s forwards cubic-bezier(.2,.8,.2,1)}@keyframes chest-shake{0%,100%{transform:translateX(0) rotate(0)}50%{transform:translateX(-3px) rotate(-5deg)}}@keyframes coin-burst{0%{transform:translate(0,10px) scale(.5);opacity:1}100%{transform:translate(var(--tx),var(--ty)) scale(1.2);opacity:0}}`]
})
export class TreasureChestButtonComponent { state='idle';handleClick(){if(this.state!=='idle')return;this.state='shaking';setTimeout(()=>this.state='open',1200);setTimeout(()=>this.state='idle',4500);}}LWC — HTML template
<template><button class="btn-chest" onclick={handleClick} disabled={disabled}>
<span class="chest-icon">{icon}</span>
<span class="text">{label}</span>
</button></template>LWC — JavaScript
import { LightningElement } from 'lwc';
export default class TreasureChestButton extends LightningElement {
state = 'idle';
get disabled() { return this.state !== 'idle'; }
get icon() { return this.state==='open' ? '🎁' : '🧰'; }
get label() { return this.state==='open' ? 'Claimed!' : this.state==='shaking' ? 'Unlocking...' : 'Claim Reward'; }
handleClick() {
if (this.state !== 'idle') return;
this.state = 'shaking';
const btn = this.template.querySelector('button');
btn.classList.add('is-shaking');
setTimeout(() => { btn.classList.remove('is-shaking'); btn.classList.add('is-open'); this.state = 'open'; for(let i=0;i<12;i++){const c=document.createElement('div');c.innerText='🪙';c.classList.add('coin');c.style.setProperty('--tx',(Math.random()-0.5)*150+'px');c.style.setProperty('--ty',-40-Math.random()*80+'px');btn.appendChild(c);} }, 1200);
setTimeout(() => { btn.classList.remove('is-open'); btn.querySelectorAll('.coin').forEach(c=>c.remove()); this.state = 'idle'; }, 4500);
}
}LWC — CSS
.btn-chest{width:160px;height:50px;border-radius:12px;border:none;background:#b45309;color:#fff;font-size:16px;font-weight:700;cursor:pointer;display:flex;align-items:center;justify-content:center;gap:8px;overflow:visible;transition:all .4s cubic-bezier(.4,0,.2,1);box-shadow:0 4px 15px rgba(180,83,9,.4)}.btn-chest .chest-icon{font-size:20px}.btn-chest.is-shaking{animation:chest-shake .2s infinite}.btn-chest.is-open{background:#f59e0b;color:#000;box-shadow:0 0 25px rgba(245,158,11,.8)}.coin{position:absolute;font-size:16px;opacity:0;pointer-events:none}.is-open .coin{animation:coin-burst .8s forwards cubic-bezier(.2,.8,.2,1)}@keyframes chest-shake{0%,100%{transform:translateX(0) rotate(0)}50%{transform:translateX(-3px) rotate(-5deg)}}@keyframes coin-burst{0%{transform:translate(0,10px) scale(.5);opacity:1}100%{transform:translate(var(--tx),var(--ty)) scale(1.2);opacity:0}}LWC — Configuration
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets><target>lightning__AppPage</target><target>lightning__RecordPage</target><target>lightning__HomePage</target></targets>
</LightningComponentBundle>Where Treasure Chest fits
- Reward
- Claim
- Prize
- Achievement
- Bonus
Interaction states & animations
- Shake Rattle
- Chest Open
- Coin Burst
- Gold Glow
Topics
- #treasure
- #chest
- #coins
- #reward
- #gold
- #burst
- #claim
Accessibility notes
Coin burst is decorative. Announce state changes via aria-live.
Browser support
- All modern browsers