Sticker Peel
A tactile sticker sealed over a black box lid. Pull any corner to fold the paper back along a live crease with its underside and shadow, revealing a promo code underneath before snapping back.
- Particles & fun
- Free
- css
- physics
- Added Oct 17, 2026
<style>
/* Sticker Peel by @codinvisual · t.me/CodinVisual · page shell, only needed while this file is the whole page */
</style>
<!-- sticker start -->
<div class="sp">
<canvas class="sp-grain" aria-hidden="true"></canvas>
<div class="sp-lid" tabindex="0" role="button" aria-label="A sticker on a box. Peel a corner to see the code under it, or press Enter."><canvas aria-hidden="true"></canvas></div>
<button class="sp-copy" type="button"><span>Copy code</span><svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M4 12h15M13.5 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
<p class="sp-hint" aria-hidden="true">Peel a corner</p>
</div>
<!-- sticker end -->
<script>
/* Sticker Peel by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
(() => {
const CODE = 'WELCOME20';
const DEAL = '20% OFF';
const GLUE = 0.55;
const SNAP = 0.7;
const root = document.querySelector('.sp');
if (!root) return;
const lid = root.querySelector('.sp-lid'), cv = lid.querySelector('canvas'), ctx = cv.getContext('2d');
const copy = root.querySelector('.sp-copy'), copyLabel = copy.querySelector('span'), hint = root.querySelector('.sp-hint'), grain = root.querySelector('.sp-grain');
const calm = matchMedia('(prefers-reduced-motion: reduce)');
let seed = 1017;
const rnd = () => {
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
const PAD = 40;
let W = 0, H = 0, DPR = 1, box = null, sticker = null, front = null, back = null, print = null;
function make(w, h) { const c = document.createElement('canvas'); c.width = Math.ceil(w); c.height = Math.ceil(h); return c; }
function rounded(x, p, w, h, r) { x.beginPath(); x.roundRect ? x.roundRect(p.x, p.y, w, h, r) : x.rect(p.x, p.y, w, h); }
function noise(x, w, h, a) {
const img = x.getImageData(0, 0, w, h), d = img.data;
for (let i = 0; i < d.length; i += 4) { const n = (rnd() - .5) * a; d[i] += n; d[i + 1] += n; d[i + 2] += n; }
x.putImageData(img, 0, 0);
}
// the parts are drawn once: the matte lid with its print, the face of the sticker, its back
function paint() {
const w = sticker.w * DPR, h = sticker.h * DPR, s = w / 300;
print = make(w, h); front = make(w, h); back = make(w, h);
let x = print.getContext('2d');
const foil = x.createLinearGradient(0, 0, w, h);
foil.addColorStop(0, '#F6DCA6'); foil.addColorStop(.35, '#E9C27F'); foil.addColorStop(.55, '#B88844'); foil.addColorStop(.75, '#F0D29A'); foil.addColorStop(1, '#A87A3A');
x.fillStyle = foil; x.textAlign = 'center'; x.textBaseline = 'middle';
x.font = `900 ${58 * s}px system-ui, sans-serif`; x.fillText(DEAL, w / 2, h * .4);
x.font = `700 ${22 * s}px system-ui, sans-serif`;
x.save(); x.translate(w / 2, h * .66); x.fillText(CODE.split('').join(String.fromCharCode(8202)), 0, 0); x.restore();
x.fillStyle = 'rgba(233,194,127,.6)'; x.font = `600 ${11 * s}px system-ui, sans-serif`; x.fillText('Your Brand · on your first order', w / 2, h * .82);
x = front.getContext('2d');
const paper = x.createLinearGradient(0, 0, w, h);
paper.addColorStop(0, '#F6F1E6'); paper.addColorStop(1, '#E7DFCD');
x.fillStyle = paper; x.fillRect(0, 0, w, h);
noise(x, w, h, 10);
x.strokeStyle = 'rgba(29,27,25,.85)'; x.lineWidth = 1.4 * s; x.strokeRect(10 * s, 10 * s, w - 20 * s, h - 20 * s);
x.fillStyle = '#1D1B19'; x.textAlign = 'center'; x.textBaseline = 'middle';
x.font = `600 ${11 * s}px system-ui, sans-serif`; x.fillText('Your Brand', w / 2, h * .2);
x.font = `900 ${44 * s}px system-ui, sans-serif`; x.fillText('Peel here', w / 2, h * .52);
x.font = `500 ${12 * s}px system-ui, sans-serif`; x.fillStyle = 'rgba(29,27,25,.7)'; x.fillText('there is something for you under it', w / 2, h * .72);
x.strokeStyle = '#1D1B19'; x.lineWidth = 1.6 * s; x.lineCap = 'round';
x.beginPath(); x.moveTo(w - 46 * s, h - 24 * s); x.quadraticCurveTo(w - 26 * s, h - 26 * s, w - 24 * s, h - 46 * s); x.stroke();
x.beginPath(); x.moveTo(w - 30 * s, h - 42 * s); x.lineTo(w - 24 * s, h - 47 * s); x.lineTo(w - 19 * s, h - 41 * s); x.stroke();
x = back.getContext('2d');
x.fillStyle = '#FBF8F2'; x.fillRect(0, 0, w, h);
// the back keeps a faint print of the glue it left
x.strokeStyle = 'rgba(160,150,135,.13)'; x.lineWidth = 1 * s;
for (let k = -h; k < w; k += 9 * s) { x.beginPath(); x.moveTo(k, 0); x.lineTo(k + h, h); x.stroke(); }
noise(x, w, h, 8);
}
function setup() {
const w = lid.clientWidth, h = lid.clientHeight;
if (!w || !h || (w === W && h === H)) return;
W = w; H = h; DPR = Math.min(2, window.devicePixelRatio || 1);
cv.width = Math.round((W + PAD * 2) * DPR); cv.height = Math.round((H + PAD * 2) * DPR);
box = { x: PAD, y: PAD, w: W, h: H };
const sw = W * .62, sh = sw * .6;
sticker = { x: PAD + (W - sw) / 2, y: PAD + (H - sh) / 2, w: sw, h: sh, r: 12 };
paint();
grain.width = Math.round(root.clientWidth / 2); grain.height = Math.round(root.clientHeight / 2);
const gc = grain.getContext('2d'), gi = gc.createImageData(grain.width, grain.height);
for (let i = 0; i < gi.data.length; i += 4) { const v = rnd() * 255; gi.data[i] = gi.data[i + 1] = gi.data[i + 2] = v; gi.data[i + 3] = 12; }
gc.putImageData(gi, 0, 0);
lidTex = null;
}
let lidTex = null;
function lidImage() {
if (lidTex) return lidTex;
lidTex = make(cv.width, cv.height);
const x = lidTex.getContext('2d');
x.setTransform(DPR, 0, 0, DPR, 0, 0);
x.shadowColor = 'rgba(0,0,0,.7)'; x.shadowBlur = 34 * DPR; x.shadowOffsetY = 18 * DPR;
rounded(x, box, box.w, box.h, 22); x.fillStyle = '#131316'; x.fill();
x.shadowColor = 'transparent';
const top = x.createLinearGradient(box.x, box.y, box.x + box.w * .6, box.y + box.h);
top.addColorStop(0, 'rgba(255,240,220,.07)'); top.addColorStop(1, 'rgba(255,240,220,0)');
rounded(x, box, box.w, box.h, 22); x.fillStyle = top; x.fill();
x.strokeStyle = 'rgba(255,255,255,.08)'; x.lineWidth = 1; rounded(x, { x: box.x + .5, y: box.y + .5 }, box.w - 1, box.h - 1, 22); x.stroke();
x.setTransform(1, 0, 0, 1, 0, 0);
noise(x, lidTex.width, lidTex.height, 7);
return lidTex;
}
// the peel: the corner C has been pulled to P, the crease is halfway between them, square to the pull
const corners = () => [{ x: sticker.x, y: sticker.y }, { x: sticker.x + sticker.w, y: sticker.y }, { x: sticker.x + sticker.w, y: sticker.y + sticker.h }, { x: sticker.x, y: sticker.y + sticker.h }];
let corner = null, dir = { x: 0, y: 0 }, pull = 0, speed = 0, held = false, wish = 0, hover = null;
const diag = () => Math.hypot(sticker.w, sticker.h);
function grabAt(x, y) {
let best = null, bd = 1e9;
for (const c of corners()) { const d = Math.hypot(c.x - x, c.y - y); if (d < bd) { bd = d; best = c; } }
return best;
}
// the way into the sticker from a corner; a pull never points outward, or the crease would leave the paper
function inward(c) { const v = { x: sticker.x + sticker.w / 2 - c.x, y: sticker.y + sticker.h / 2 - c.y }, d = Math.hypot(v.x, v.y); return { x: v.x / d, y: v.y / d }; }
function aim(x, y) {
const v = { x: x - corner.x, y: y - corner.y }, d = Math.hypot(v.x, v.y);
if (d < 1) return;
const inn = inward(corner);
let u = { x: v.x / d, y: v.y / d }, along = u.x * inn.x + u.y * inn.y;
if (along < .25) { const a = .25 - along; u = { x: u.x + inn.x * a * 1.6, y: u.y + inn.y * a * 1.6 }; const l = Math.hypot(u.x, u.y); u = { x: u.x / l, y: u.y / l }; }
dir = u;
// the glue holds: most of the way the corner stays under the hand, near the end it lags more and more
const reach = diag() * 1.6, free = diag(), hold = 1 - GLUE * .6;
const over = Math.max(0, d - free), room = reach - free;
const give = 1 - Math.exp(-over * hold / room);
wish = Math.min(d, free) + room * give;
}
const local = e => { const r = lid.getBoundingClientRect(); return { x: e.clientX - r.left + PAD, y: e.clientY - r.top + PAD }; };
lid.addEventListener('pointerdown', e => {
const p = local(e);
corner = grabAt(p.x, p.y); held = true; peeked = true;
try { lid.setPointerCapture(e.pointerId); } catch (err) { }
aim(p.x, p.y);
});
lid.addEventListener('pointermove', e => {
const p = local(e);
if (held) return aim(p.x, p.y);
// a hand near a corner lifts it a little, as an invitation
const c = grabAt(p.x, p.y), near = Math.hypot(c.x - p.x, c.y - p.y) < 60;
hover = near ? c : null;
if (near && pull < 14) { corner = c; dir = inward(c); wish = 12; }
else if (!near && wish <= 12) wish = 0;
});
const letGo = () => { if (held) { held = false; wish = 0; } };
lid.addEventListener('pointerup', letGo);
lid.addEventListener('pointercancel', letGo);
lid.addEventListener('pointerleave', () => { hover = null; if (!held && wish <= 12) wish = 0; });
lid.addEventListener('keydown', e => {
if (e.key !== 'Enter' && e.key !== ' ') return;
e.preventDefault(); peeked = true;
if (wish > 0) { wish = 0; return; }
corner = corners()[2]; dir = inward(corner); wish = diag() * .8;
});
let peeked = false, copiedAt = 0, clipboard = navigator.clipboard;
copy.addEventListener('click', async () => {
try { await clipboard.writeText(CODE); }
catch (err) { const t = document.createElement('textarea'); t.value = CODE; document.body.append(t); t.select(); document.execCommand('copy'); t.remove(); }
copyLabel.textContent = 'Copied'; copiedAt = performance.now();
});
function frame(now) {
const dt = Math.min(.05, frame.t ? (now - frame.t) / 1000 : .016);
frame.t = now;
requestAnimationFrame(frame);
if (!W) return;
// held, the paper follows the hand; let go, a spring lays it back and it snaps flat
for (let s = 0; s < Math.max(1, Math.round(dt * 120)); s++) {
const h = dt / Math.max(1, Math.round(dt * 120));
if (held || wish > 0 && wish <= 12) { speed = 0; pull += (wish - pull) * Math.min(1, h * 22); }
else if (calm.matches) { pull += (wish - pull) * Math.min(1, h * 9); speed = 0; }
else {
const spring = -(pull - wish) * 260;
const drag = speed * 2 * (1 - SNAP * .55) * 16;
speed += (spring - drag) * h;
pull += speed * h;
if (pull < 0) {
pull = -pull * .25; speed = -speed * .25;
}
}
}
if (pull < .3 && !held && wish === 0) pull = 0;
draw(now / 1000);
hint.style.opacity = peeked ? '0' : '1';
if (copiedAt && now - copiedAt > 1400) { copiedAt = 0; copyLabel.textContent = 'Copy code'; }
}
function halfPlane(x, m, n, side) {
const t = { x: -n.y, y: n.x }, L = 4000;
x.beginPath();
x.moveTo(m.x + t.x * L, m.y + t.y * L);
x.lineTo(m.x + t.x * L + n.x * L * side, m.y + t.y * L + n.y * L * side);
x.lineTo(m.x - t.x * L + n.x * L * side, m.y - t.y * L + n.y * L * side);
x.lineTo(m.x - t.x * L, m.y - t.y * L);
x.closePath();
}
function draw(time) {
const x = ctx;
x.setTransform(1, 0, 0, 1, 0, 0);
x.clearRect(0, 0, cv.width, cv.height);
x.drawImage(lidImage(), 0, 0);
x.setTransform(DPR, 0, 0, DPR, 0, 0);
// the print on the box is always there, the sticker covers it
x.save(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip();
x.fillStyle = '#0F0F11'; x.fillRect(sticker.x, sticker.y, sticker.w, sticker.h);
x.drawImage(print, sticker.x, sticker.y, sticker.w, sticker.h);
x.restore();
if (pull < .5 || !corner) {
x.save(); x.shadowColor = 'rgba(0,0,0,.35)'; x.shadowBlur = 4; x.shadowOffsetY = 1;
rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.fillStyle = '#EDE6D6'; x.fill(); x.restore();
x.save(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip(); x.drawImage(front, sticker.x, sticker.y, sticker.w, sticker.h); x.restore();
return;
}
// a little tremble along the crease while the glue is stretched
const strain = held ? Math.min(1, pull / diag()) : 0, wob = strain * .6 * Math.sin(time * 61);
const P = { x: corner.x + dir.x * (pull + wob), y: corner.y + dir.y * (pull + wob) };
const m = { x: (corner.x + P.x) / 2, y: (corner.y + P.y) / 2 }, n = dir;
// the part still stuck down
x.save(); halfPlane(x, m, n, 1); x.clip();
x.save(); x.shadowColor = 'rgba(0,0,0,.35)'; x.shadowBlur = 4; x.shadowOffsetY = 1;
rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.fillStyle = '#EDE6D6'; x.fill(); x.restore();
rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip(); x.drawImage(front, sticker.x, sticker.y, sticker.w, sticker.h);
x.restore();
// the flap: the lifted part mirrored over the crease, back side up, with its shadow on the box
const d = n.x * m.x + n.y * m.y;
x.save();
x.transform(1 - 2 * n.x * n.x, -2 * n.x * n.y, -2 * n.x * n.y, 1 - 2 * n.y * n.y, 2 * d * n.x, 2 * d * n.y);
halfPlane(x, m, n, -1); x.clip();
x.save();
const lift = Math.min(1, pull / 60);
x.shadowColor = `rgba(0,0,0,${(.45 * lift).toFixed(3)})`; x.shadowBlur = (6 + 16 * lift) * DPR;
// the shadow falls away from the crease, onto what the flap now covers
const off = (4 + 10 * lift);
x.shadowOffsetX = (n.x * off + 2) * DPR; x.shadowOffsetY = (n.y * off + 6) * DPR; // shadow offsets ignore the mirror, they are in screen pixels
rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.fillStyle = '#F7F3EA'; x.fill();
x.restore();
rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip();
x.drawImage(back, sticker.x, sticker.y, sticker.w, sticker.h);
// the bend catches the light right at the crease and falls off into the flap
const g = x.createLinearGradient(m.x, m.y, m.x - n.x * 60, m.y - n.y * 60);
g.addColorStop(0, 'rgba(255,255,255,.75)'); g.addColorStop(.12, 'rgba(255,255,255,.15)'); g.addColorStop(.5, 'rgba(120,105,85,.10)'); g.addColorStop(1, 'rgba(120,105,85,0)');
x.fillStyle = g; x.fillRect(sticker.x - 200, sticker.y - 200, sticker.w + 400, sticker.h + 400);
x.restore();
// a dark line where the paper folds over itself
const t = { x: -n.y, y: n.x };
x.save(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip();
const crease = x.createLinearGradient(m.x, m.y, m.x + n.x * 10, m.y + n.y * 10);
crease.addColorStop(0, 'rgba(0,0,0,.22)'); crease.addColorStop(1, 'rgba(0,0,0,0)');
x.fillStyle = crease; x.beginPath(); x.moveTo(m.x + t.x * 900, m.y + t.y * 900); x.lineTo(m.x - t.x * 900, m.y - t.y * 900); x.lineTo(m.x - t.x * 900 + n.x * 10, m.y - t.y * 900 + n.y * 10); x.lineTo(m.x + t.x * 900 + n.x * 10, m.y + t.y * 900 + n.y * 10); x.fill();
x.restore();
}
new ResizeObserver(setup).observe(lid);
setup();
requestAnimationFrame(frame);
})();
</script>
Grab any corner of the sticker and peel it back to uncover the code, then click Copy code.
What you can change
Change a number, save, and reload the page to see the difference.
CODEWELCOME20The promo code printed under the sticker and copied by the button.
DEAL20% OFFThe headline revealed underneath the sticker.
GLUE0.55How hard the glue holds, from 0 free peel to 1 tight hold.
SNAP0.7How lively the sticker snaps back when released.
Add it to your site
Use for promo code reveals, welcome discounts, Easter eggs or product launch drops.
CSS
Paste into your stylesheet, or inside a <style> tag in <head>.
/* Sticker Peel by @codinvisual · t.me/CodinVisual · page shell, only needed while this file is the whole page */HTML
Put it where the effect should appear on your page.
<!-- sticker start --> <div class="sp"> <canvas class="sp-grain" aria-hidden="true"></canvas> <div class="sp-lid" tabindex="0" role="button" aria-label="A sticker on a box. Peel a corner to see the code under it, or press Enter."><canvas aria-hidden="true"></canvas></div> <button class="sp-copy" type="button"><span>Copy code</span><svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M4 12h15M13.5 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"/></svg></button> <p class="sp-hint" aria-hidden="true">Peel a corner</p> </div> <!-- sticker end -->JavaScript
Paste right before the closing </body> tag, inside <script></script>.
/* Sticker Peel by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ (() => { const CODE = 'WELCOME20'; const DEAL = '20% OFF'; const GLUE = 0.55; const SNAP = 0.7; const root = document.querySelector('.sp'); if (!root) return; const lid = root.querySelector('.sp-lid'), cv = lid.querySelector('canvas'), ctx = cv.getContext('2d'); const copy = root.querySelector('.sp-copy'), copyLabel = copy.querySelector('span'), hint = root.querySelector('.sp-hint'), grain = root.querySelector('.sp-grain'); const calm = matchMedia('(prefers-reduced-motion: reduce)'); let seed = 1017; const rnd = () => { seed = seed + 0x6D2B79F5 | 0; let t = Math.imul(seed ^ seed >>> 15, 1 | seed); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; const PAD = 40; let W = 0, H = 0, DPR = 1, box = null, sticker = null, front = null, back = null, print = null; function make(w, h) { const c = document.createElement('canvas'); c.width = Math.ceil(w); c.height = Math.ceil(h); return c; } function rounded(x, p, w, h, r) { x.beginPath(); x.roundRect ? x.roundRect(p.x, p.y, w, h, r) : x.rect(p.x, p.y, w, h); } function noise(x, w, h, a) { const img = x.getImageData(0, 0, w, h), d = img.data; for (let i = 0; i < d.length; i += 4) { const n = (rnd() - .5) * a; d[i] += n; d[i + 1] += n; d[i + 2] += n; } x.putImageData(img, 0, 0); } // the parts are drawn once: the matte lid with its print, the face of the sticker, its back function paint() { const w = sticker.w * DPR, h = sticker.h * DPR, s = w / 300; print = make(w, h); front = make(w, h); back = make(w, h); let x = print.getContext('2d'); const foil = x.createLinearGradient(0, 0, w, h); foil.addColorStop(0, '#F6DCA6'); foil.addColorStop(.35, '#E9C27F'); foil.addColorStop(.55, '#B88844'); foil.addColorStop(.75, '#F0D29A'); foil.addColorStop(1, '#A87A3A'); x.fillStyle = foil; x.textAlign = 'center'; x.textBaseline = 'middle'; x.font = `900 ${58 * s}px system-ui, sans-serif`; x.fillText(DEAL, w / 2, h * .4); x.font = `700 ${22 * s}px system-ui, sans-serif`; x.save(); x.translate(w / 2, h * .66); x.fillText(CODE.split('').join(String.fromCharCode(8202)), 0, 0); x.restore(); x.fillStyle = 'rgba(233,194,127,.6)'; x.font = `600 ${11 * s}px system-ui, sans-serif`; x.fillText('Your Brand · on your first order', w / 2, h * .82); x = front.getContext('2d'); const paper = x.createLinearGradient(0, 0, w, h); paper.addColorStop(0, '#F6F1E6'); paper.addColorStop(1, '#E7DFCD'); x.fillStyle = paper; x.fillRect(0, 0, w, h); noise(x, w, h, 10); x.strokeStyle = 'rgba(29,27,25,.85)'; x.lineWidth = 1.4 * s; x.strokeRect(10 * s, 10 * s, w - 20 * s, h - 20 * s); x.fillStyle = '#1D1B19'; x.textAlign = 'center'; x.textBaseline = 'middle'; x.font = `600 ${11 * s}px system-ui, sans-serif`; x.fillText('Your Brand', w / 2, h * .2); x.font = `900 ${44 * s}px system-ui, sans-serif`; x.fillText('Peel here', w / 2, h * .52); x.font = `500 ${12 * s}px system-ui, sans-serif`; x.fillStyle = 'rgba(29,27,25,.7)'; x.fillText('there is something for you under it', w / 2, h * .72); x.strokeStyle = '#1D1B19'; x.lineWidth = 1.6 * s; x.lineCap = 'round'; x.beginPath(); x.moveTo(w - 46 * s, h - 24 * s); x.quadraticCurveTo(w - 26 * s, h - 26 * s, w - 24 * s, h - 46 * s); x.stroke(); x.beginPath(); x.moveTo(w - 30 * s, h - 42 * s); x.lineTo(w - 24 * s, h - 47 * s); x.lineTo(w - 19 * s, h - 41 * s); x.stroke(); x = back.getContext('2d'); x.fillStyle = '#FBF8F2'; x.fillRect(0, 0, w, h); // the back keeps a faint print of the glue it left x.strokeStyle = 'rgba(160,150,135,.13)'; x.lineWidth = 1 * s; for (let k = -h; k < w; k += 9 * s) { x.beginPath(); x.moveTo(k, 0); x.lineTo(k + h, h); x.stroke(); } noise(x, w, h, 8); } function setup() { const w = lid.clientWidth, h = lid.clientHeight; if (!w || !h || (w === W && h === H)) return; W = w; H = h; DPR = Math.min(2, window.devicePixelRatio || 1); cv.width = Math.round((W + PAD * 2) * DPR); cv.height = Math.round((H + PAD * 2) * DPR); box = { x: PAD, y: PAD, w: W, h: H }; const sw = W * .62, sh = sw * .6; sticker = { x: PAD + (W - sw) / 2, y: PAD + (H - sh) / 2, w: sw, h: sh, r: 12 }; paint(); grain.width = Math.round(root.clientWidth / 2); grain.height = Math.round(root.clientHeight / 2); const gc = grain.getContext('2d'), gi = gc.createImageData(grain.width, grain.height); for (let i = 0; i < gi.data.length; i += 4) { const v = rnd() * 255; gi.data[i] = gi.data[i + 1] = gi.data[i + 2] = v; gi.data[i + 3] = 12; } gc.putImageData(gi, 0, 0); lidTex = null; } let lidTex = null; function lidImage() { if (lidTex) return lidTex; lidTex = make(cv.width, cv.height); const x = lidTex.getContext('2d'); x.setTransform(DPR, 0, 0, DPR, 0, 0); x.shadowColor = 'rgba(0,0,0,.7)'; x.shadowBlur = 34 * DPR; x.shadowOffsetY = 18 * DPR; rounded(x, box, box.w, box.h, 22); x.fillStyle = '#131316'; x.fill(); x.shadowColor = 'transparent'; const top = x.createLinearGradient(box.x, box.y, box.x + box.w * .6, box.y + box.h); top.addColorStop(0, 'rgba(255,240,220,.07)'); top.addColorStop(1, 'rgba(255,240,220,0)'); rounded(x, box, box.w, box.h, 22); x.fillStyle = top; x.fill(); x.strokeStyle = 'rgba(255,255,255,.08)'; x.lineWidth = 1; rounded(x, { x: box.x + .5, y: box.y + .5 }, box.w - 1, box.h - 1, 22); x.stroke(); x.setTransform(1, 0, 0, 1, 0, 0); noise(x, lidTex.width, lidTex.height, 7); return lidTex; } // the peel: the corner C has been pulled to P, the crease is halfway between them, square to the pull const corners = () => [{ x: sticker.x, y: sticker.y }, { x: sticker.x + sticker.w, y: sticker.y }, { x: sticker.x + sticker.w, y: sticker.y + sticker.h }, { x: sticker.x, y: sticker.y + sticker.h }]; let corner = null, dir = { x: 0, y: 0 }, pull = 0, speed = 0, held = false, wish = 0, hover = null; const diag = () => Math.hypot(sticker.w, sticker.h); function grabAt(x, y) { let best = null, bd = 1e9; for (const c of corners()) { const d = Math.hypot(c.x - x, c.y - y); if (d < bd) { bd = d; best = c; } } return best; } // the way into the sticker from a corner; a pull never points outward, or the crease would leave the paper function inward(c) { const v = { x: sticker.x + sticker.w / 2 - c.x, y: sticker.y + sticker.h / 2 - c.y }, d = Math.hypot(v.x, v.y); return { x: v.x / d, y: v.y / d }; } function aim(x, y) { const v = { x: x - corner.x, y: y - corner.y }, d = Math.hypot(v.x, v.y); if (d < 1) return; const inn = inward(corner); let u = { x: v.x / d, y: v.y / d }, along = u.x * inn.x + u.y * inn.y; if (along < .25) { const a = .25 - along; u = { x: u.x + inn.x * a * 1.6, y: u.y + inn.y * a * 1.6 }; const l = Math.hypot(u.x, u.y); u = { x: u.x / l, y: u.y / l }; } dir = u; // the glue holds: most of the way the corner stays under the hand, near the end it lags more and more const reach = diag() * 1.6, free = diag(), hold = 1 - GLUE * .6; const over = Math.max(0, d - free), room = reach - free; const give = 1 - Math.exp(-over * hold / room); wish = Math.min(d, free) + room * give; } const local = e => { const r = lid.getBoundingClientRect(); return { x: e.clientX - r.left + PAD, y: e.clientY - r.top + PAD }; }; lid.addEventListener('pointerdown', e => { const p = local(e); corner = grabAt(p.x, p.y); held = true; peeked = true; try { lid.setPointerCapture(e.pointerId); } catch (err) { } aim(p.x, p.y); }); lid.addEventListener('pointermove', e => { const p = local(e); if (held) return aim(p.x, p.y); // a hand near a corner lifts it a little, as an invitation const c = grabAt(p.x, p.y), near = Math.hypot(c.x - p.x, c.y - p.y) < 60; hover = near ? c : null; if (near && pull < 14) { corner = c; dir = inward(c); wish = 12; } else if (!near && wish <= 12) wish = 0; }); const letGo = () => { if (held) { held = false; wish = 0; } }; lid.addEventListener('pointerup', letGo); lid.addEventListener('pointercancel', letGo); lid.addEventListener('pointerleave', () => { hover = null; if (!held && wish <= 12) wish = 0; }); lid.addEventListener('keydown', e => { if (e.key !== 'Enter' && e.key !== ' ') return; e.preventDefault(); peeked = true; if (wish > 0) { wish = 0; return; } corner = corners()[2]; dir = inward(corner); wish = diag() * .8; }); let peeked = false, copiedAt = 0, clipboard = navigator.clipboard; copy.addEventListener('click', async () => { try { await clipboard.writeText(CODE); } catch (err) { const t = document.createElement('textarea'); t.value = CODE; document.body.append(t); t.select(); document.execCommand('copy'); t.remove(); } copyLabel.textContent = 'Copied'; copiedAt = performance.now(); }); function frame(now) { const dt = Math.min(.05, frame.t ? (now - frame.t) / 1000 : .016); frame.t = now; requestAnimationFrame(frame); if (!W) return; // held, the paper follows the hand; let go, a spring lays it back and it snaps flat for (let s = 0; s < Math.max(1, Math.round(dt * 120)); s++) { const h = dt / Math.max(1, Math.round(dt * 120)); if (held || wish > 0 && wish <= 12) { speed = 0; pull += (wish - pull) * Math.min(1, h * 22); } else if (calm.matches) { pull += (wish - pull) * Math.min(1, h * 9); speed = 0; } else { const spring = -(pull - wish) * 260; const drag = speed * 2 * (1 - SNAP * .55) * 16; speed += (spring - drag) * h; pull += speed * h; if (pull < 0) { pull = -pull * .25; speed = -speed * .25; } } } if (pull < .3 && !held && wish === 0) pull = 0; draw(now / 1000); hint.style.opacity = peeked ? '0' : '1'; if (copiedAt && now - copiedAt > 1400) { copiedAt = 0; copyLabel.textContent = 'Copy code'; } } function halfPlane(x, m, n, side) { const t = { x: -n.y, y: n.x }, L = 4000; x.beginPath(); x.moveTo(m.x + t.x * L, m.y + t.y * L); x.lineTo(m.x + t.x * L + n.x * L * side, m.y + t.y * L + n.y * L * side); x.lineTo(m.x - t.x * L + n.x * L * side, m.y - t.y * L + n.y * L * side); x.lineTo(m.x - t.x * L, m.y - t.y * L); x.closePath(); } function draw(time) { const x = ctx; x.setTransform(1, 0, 0, 1, 0, 0); x.clearRect(0, 0, cv.width, cv.height); x.drawImage(lidImage(), 0, 0); x.setTransform(DPR, 0, 0, DPR, 0, 0); // the print on the box is always there, the sticker covers it x.save(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip(); x.fillStyle = '#0F0F11'; x.fillRect(sticker.x, sticker.y, sticker.w, sticker.h); x.drawImage(print, sticker.x, sticker.y, sticker.w, sticker.h); x.restore(); if (pull < .5 || !corner) { x.save(); x.shadowColor = 'rgba(0,0,0,.35)'; x.shadowBlur = 4; x.shadowOffsetY = 1; rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.fillStyle = '#EDE6D6'; x.fill(); x.restore(); x.save(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip(); x.drawImage(front, sticker.x, sticker.y, sticker.w, sticker.h); x.restore(); return; } // a little tremble along the crease while the glue is stretched const strain = held ? Math.min(1, pull / diag()) : 0, wob = strain * .6 * Math.sin(time * 61); const P = { x: corner.x + dir.x * (pull + wob), y: corner.y + dir.y * (pull + wob) }; const m = { x: (corner.x + P.x) / 2, y: (corner.y + P.y) / 2 }, n = dir; // the part still stuck down x.save(); halfPlane(x, m, n, 1); x.clip(); x.save(); x.shadowColor = 'rgba(0,0,0,.35)'; x.shadowBlur = 4; x.shadowOffsetY = 1; rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.fillStyle = '#EDE6D6'; x.fill(); x.restore(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip(); x.drawImage(front, sticker.x, sticker.y, sticker.w, sticker.h); x.restore(); // the flap: the lifted part mirrored over the crease, back side up, with its shadow on the box const d = n.x * m.x + n.y * m.y; x.save(); x.transform(1 - 2 * n.x * n.x, -2 * n.x * n.y, -2 * n.x * n.y, 1 - 2 * n.y * n.y, 2 * d * n.x, 2 * d * n.y); halfPlane(x, m, n, -1); x.clip(); x.save(); const lift = Math.min(1, pull / 60); x.shadowColor = `rgba(0,0,0,${(.45 * lift).toFixed(3)})`; x.shadowBlur = (6 + 16 * lift) * DPR; // the shadow falls away from the crease, onto what the flap now covers const off = (4 + 10 * lift); x.shadowOffsetX = (n.x * off + 2) * DPR; x.shadowOffsetY = (n.y * off + 6) * DPR; // shadow offsets ignore the mirror, they are in screen pixels rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.fillStyle = '#F7F3EA'; x.fill(); x.restore(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip(); x.drawImage(back, sticker.x, sticker.y, sticker.w, sticker.h); // the bend catches the light right at the crease and falls off into the flap const g = x.createLinearGradient(m.x, m.y, m.x - n.x * 60, m.y - n.y * 60); g.addColorStop(0, 'rgba(255,255,255,.75)'); g.addColorStop(.12, 'rgba(255,255,255,.15)'); g.addColorStop(.5, 'rgba(120,105,85,.10)'); g.addColorStop(1, 'rgba(120,105,85,0)'); x.fillStyle = g; x.fillRect(sticker.x - 200, sticker.y - 200, sticker.w + 400, sticker.h + 400); x.restore(); // a dark line where the paper folds over itself const t = { x: -n.y, y: n.x }; x.save(); rounded(x, sticker, sticker.w, sticker.h, sticker.r); x.clip(); const crease = x.createLinearGradient(m.x, m.y, m.x + n.x * 10, m.y + n.y * 10); crease.addColorStop(0, 'rgba(0,0,0,.22)'); crease.addColorStop(1, 'rgba(0,0,0,0)'); x.fillStyle = crease; x.beginPath(); x.moveTo(m.x + t.x * 900, m.y + t.y * 900); x.lineTo(m.x - t.x * 900, m.y - t.y * 900); x.lineTo(m.x - t.x * 900 + n.x * 10, m.y - t.y * 900 + n.y * 10); x.lineTo(m.x + t.x * 900 + n.x * 10, m.y + t.y * 900 + n.y * 10); x.fill(); x.restore(); } new ResizeObserver(setup).observe(lid); setup(); requestAnimationFrame(frame); })();
Connect it to your backend
Pure front end interaction; pass your dynamic promo code into CODE.
Good to know
- Keyboard accessible: Tab to the sticker and press Enter to peel and lay it back down.
Tilda, Webflow, WordPress
Press Copy all code at the top and paste it into one HTML block.
Add block, Other, T123 HTML code. Paste and save. Check the published page, the editor preview does not run scripts.
Add panel, Embed. Paste, then Save & Close. Custom code runs on the published site.
Add block, Custom HTML. Paste and press Update.



