Ballot Box Vote Counter

Ballot cards slide one by one into a clear ballot box while a vote counter ticks up per card.

Motion specs

Duration
7s loop
Easing
cubic-bezier(.55,0,.85,.36)
Technique
DOM + WAAPI
Library
Vanilla JS + WAAPI
Category
Animated Infographics
License
Free for personal and commercial use
AI prompt
Create a professional web motion called "Ballot Box Vote Counter" (صندوق الاقتراع وعداد الأصوات).
• Target: عناصر DOM
• Duration: 7s loop
• Easing: cubic-bezier(.55,0,.85,.36)
• Colors: dark charcoal background #0d0e11, surface #1e2129, white text #f3f4f6, and one fiery orange accent #ff5e1a
• Direction: بطاقات تصويت تنزلق واحدة تلو الأخرى داخل صندوق شفاف والعداد يرتفع مع كل بطاقة
• Library / technique: DOM + WAAPI
• Output format: a fully self-contained HTML5 / CSS3 / vanilla JS file
• Behavior: Paper ballot cards drop one after another through the slot of a transparent ballot box. With each card that lands, the vote counter above jumps by one with a pop. After six votes the scene pauses and restarts. The animation loops automatically with a short pause between cycles.
• Performance: prefer transform and opacity, keep 60fps, no external libraries.
Full code (HTML + CSS + JS)
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Ballot Box Vote Counter</title>
  <style>
    html,body{margin:0;height:100%;background:#0d0e11;overflow:hidden}
    #stage{position:relative;width:100%;height:100vh;min-height:220px;overflow:hidden;background:#090a0d}
  </style>
</head>
<body>
  <div id="stage"></div>
  <script>
const T=["Votes", "Ballot box"];

const S=document.getElementById('stage');
const B=document.createElement('div');
B.style.cssText='position:absolute;left:50%;top:50%;width:400px;height:220px;margin:-110px 0 0 -200px;overflow:hidden;background:#0d0e11;direction:'+(document.documentElement.lang==='ar'?'rtl':'ltr')+';';
S.appendChild(B);
function fit(){const s=Math.min(innerWidth/400,innerHeight/220);B.style.transform='scale('+s+')';}
fit();addEventListener('resize',fit);
const AC='#ff5e1a',W='#f3f4f6',MU='#a1a8b3',SF='#1e2129',DK='#0d0e11';
const AR=document.documentElement.lang==='ar';
let TM=[],GEN=0;
function clr(){TM.forEach(clearTimeout);TM=[];GEN++;B.innerHTML='';}
let FB=1.3;
function el(t,css,txt,p){const e=document.createElement(t);css=(css||'').replace(/font:(\d+) (\d+(?:\.\d+)?)px/,(m,w,s)=>{s=+s;s=s<=22?s*FB:s<=34?s*(1+(FB-1)*.4):s;return 'font:'+w+' '+s.toFixed(1)+'px';});if(AR)css=css.replace('system-ui,sans-serif',"'Cairo',system-ui,sans-serif");e.style.cssText=css;if(txt!=null)e.textContent=txt;(p||B).appendChild(e);return e;}
function an(e,k,o){return e.animate(k,Object.assign({fill:'both',easing:'cubic-bezier(.16,1,.3,1)'},o||{}));}
function at(ms,f){const g=GEN;TM.push(setTimeout(()=>{if(g===GEN)f();},ms));}
function tw(ms,f,delay){const g=GEN;const st=performance.now()+(delay||0);(function s(n){if(g!==GEN)return;const p=Math.max(0,Math.min(1,(n-st)/ms));f(p,p*ms);if(n-st<ms)requestAnimationFrame(s);})(performance.now());}
function run(b){clr();const d=b();if(typeof d==='number')TM.push(setTimeout(()=>run(b),d+1200));}
const ez=p=>p<.5?2*p*p:1-Math.pow(-2*p+2,2)/2;
const NS='http://www.w3.org/2000/svg';
function sv(t,a,p){const e=document.createElementNS(NS,t);for(const k in a)e.setAttribute(k,a[k]);(p||B).appendChild(e);return e;}
function svg(){const s=sv('svg',{viewBox:'0 0 400 220',width:400,height:220});s.style.cssText='position:absolute;left:0;top:0';return s;}
function cv(){const c=el('canvas','position:absolute;left:0;top:0');c.width=400;c.height=220;return c.getContext('2d');}


run(()=>{
  el('div','position:absolute;left:0;right:0;top:16px;text-align:center;font:700 15px system-ui,sans-serif;color:'+MU,T[0]);
  const cnt=el('div','position:absolute;left:0;right:0;top:38px;text-align:center;font:900 34px system-ui,sans-serif;color:'+AC,'0');
  const bx=el('div','position:absolute;left:130px;top:100px;width:140px;height:90px;background:rgba(30,33,41,.55);border:2px solid '+AC+';border-radius:6px;backdrop-filter:blur(2px)');
  el('div','position:absolute;left:175px;top:92px;width:50px;height:7px;background:'+DK+';border:2px solid '+AC+';border-radius:3px');
  el('div','position:absolute;left:130px;top:192px;width:140px;text-align:center;font:700 11px system-ui,sans-serif;color:'+MU,T[1]);
  let v=0;
  for(let i=0;i<6;i++){
    at(600+i*750,()=>{
      const c=el('div','position:absolute;left:186px;top:-30px;width:28px;height:36px;background:'+W+';border-radius:2px;box-shadow:0 2px 6px rgba(0,0,0,.4)');
      el('div','position:absolute;left:8px;top:10px;width:12px;height:12px;border:2px solid '+DK+';border-radius:2px',null,c);
      el('div','position:absolute;left:10px;top:12px;width:8px;height:8px;background:'+AC+';border-radius:1px',null,c);
      an(c,[{transform:'translateY(0) rotate(0deg)',opacity:1},{transform:'translateY(105px) rotate('+(i%2?6:-6)+'deg)',opacity:1}],{duration:560,easing:'cubic-bezier(.55,0,.85,.36)'});
      an(c,[{opacity:1},{opacity:0}],{delay:560,duration:220});
      at(600+i*750+580,()=>{v++;cnt.textContent=v;an(cnt,[{transform:'scale(1.25)'},{transform:'scale(1)'}],{duration:260});});
    });
  }
  return 600+5*750+1200;
});

  </script>
</body>
</html>

Related templates