حلقة نسبة مئوية

حلقة تمتلئ حتى القيمة المطلوبة مع رقم مئوي يعدّ بالتزامن.

مواصفات الحركة

المدة
1.8s
منحنى التسارع
cubic-bezier(.16,1,.3,1)
التقنية
SVG + Counter
المكتبة
SVG + Counter
التصنيف
إنفوجرافيك متحرك
الرخصة
مجاني للاستخدام الشخصي والتجاري
أمر الذكاء الاصطناعي (AI Prompt)
أنشئ حركة ويب باسم "حلقة نسبة مئوية" (Donut Percentage Ring).
• الوصف: حلقة تمتلئ حتى القيمة المطلوبة مع رقم مئوي يعدّ بالتزامن.
• المدة: 1.8s، تتكرر تلقائياً مع توقف 1.5 ثانية بين كل دورة.
• الألوان: خلفية #0d0e11، نص #f3f4f6، لون تمييز واحد #ff5e1a.
• التقنية: SVG + Counter
• المخرج: ملف HTML/CSS/JS مستقل، تحريك transform وopacity فقط، يعمل أثناء ظهوره فقط (IntersectionObserver) ويحترم prefers-reduced-motion.
الكود الكامل (HTML + CSS + JS)
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>حلقة نسبة مئوية — Donut Percentage Ring</title>
  <style>
    body { margin: 0; background: #0d0e11; color: #f3f4f6; font-family: system-ui, sans-serif; }
    .fxn{position:relative;width:100%;height:220px;overflow:hidden;display:grid;place-items:center;font-family:system-ui,sans-serif;color:#f3f4f6}
    .fxn .i1n{position:absolute;font-size:1.6rem;font-weight:900}.fxn .i1n::after{content:'%'}
  </style>
</head>
<body>
  <div id="stage"><div class="fxn"><svg viewBox="0 0 100 100" width="120" height="120"><circle cx="50" cy="50" r="40" fill="none" stroke="#22252e" stroke-width="10"/><circle class="i1r" cx="50" cy="50" r="40" fill="none" stroke="#ff5e1a" stroke-width="10" stroke-linecap="round" pathLength="100" stroke-dasharray="100" transform="rotate(-90 50 50)"/></svg><div class="i1n">0</div></div></div>
  <script>
    function play(root){
    const q=s=>root.querySelector(s),qa=s=>[...root.querySelectorAll(s)],T=[],A=[];
    const at=(ms,f)=>{T.push(setTimeout(f,ms))};
    const an=(e,k,o={})=>{const a=e.animate(k,{duration:600,fill:'both',easing:'cubic-bezier(.16,1,.3,1)',...o});A.push(a);return a};
    const cnt=(el,to,ms,d=0)=>at(d,()=>{const s=performance.now(),id=setInterval(()=>{const p=Math.min(1,(performance.now()-s)/ms);el.textContent=Math.round(to*(1-Math.pow(1-p,3)));if(p===1)clearInterval(id)},30);T.push(id)});
    an(q('.i1r'),[{strokeDashoffset:100},{strokeDashoffset:28}],{duration:1500});cnt(q('.i1n'),72,1500);
    return()=>{T.forEach(clearTimeout);A.forEach(a=>a.cancel())};
    }
    const MS = 2400, PAUSE = 1500;
    const host = document.getElementById('stage');
    const init = host.innerHTML;
    const still = matchMedia('(prefers-reduced-motion: reduce)').matches;
    let stop = null, timer = null, shown = false;
    function run() { if (stop) stop(); host.innerHTML = init; stop = play(host.firstElementChild); }
    function loop() { run(); if (!still) timer = setTimeout(loop, MS + PAUSE); }
    new IntersectionObserver(([e]) => {
      if (e.isIntersecting && !shown) { shown = true; loop(); }
      else if (!e.isIntersecting && shown) { shown = false; clearTimeout(timer); if (stop) stop(); }
    }, { threshold: 0.1 }).observe(host);
  </script>
</body>
</html>

قوالب مشابهة