تحول الموجة المتصلة

تحديث نقاط التحكم لمنحنيات Q في كل إطار لصناعة موجة سائلة.

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

المدة
2.0s (Loop)
منحنى التسارع
sine.inOut
التقنية
Dynamic Path d
المكتبة
requestAnimationFrame + SVG Quadratic Path
التصنيف
رسم مسارات SVG والتحول الشكلي
الرخصة
مجاني للاستخدام الشخصي والتجاري
أمر الذكاء الاصطناعي (AI Prompt)
أنشئ حركة ويب احترافية باسم "تحول الموجة المتصلة" (Fluid Sine Wave Path Morph).
• العنصر المستهدف (Target): منحنى الموجة <path> (.wave-path)
• المدة (Duration): 2.0s (Loop)
• منحنى التسارع (Easing): sine.inOut
• الألوان (Colors): خلفية فحمية داكنة #0d0e11، سطح #16181e، نص أبيض #f3f4f6، ولون تمييز برتقالي ناري واحد #ff5e1a
• الاتجاه (Direction): تموج عمودي مستمر
• المكتبة/التقنية (Library): requestAnimationFrame + SVG Quadratic Path
• صيغة الإخراج (Output Format): ملف HTML5/CSS3/Vanilla JS مستقل بالكامل (Self-Contained)
• قيود الأداء (Performance): تحريك خصائص GPU الآمنة فقط (transform, opacity, clip-path, filter)، سرعة 60fps، استخدام IntersectionObserver للتشغيل عند الظهور، ودعم @media (prefers-reduced-motion: reduce).
الكود الكامل (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>تحول الموجة المتصلة — Fluid Sine Wave Path Morph</title>
  <style>
    body { margin: 0; background: #0d0e11; color: #f3f4f6; font-family: system-ui, sans-serif; }
    :root { --font-mono: ui-monospace, Menlo, Consolas, monospace; }
    #stage { position: relative; width: 100%; height: 220px; box-sizing: border-box; padding: 16px; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #090a0d; }
  </style>
</head>
<body>
  <div id="stage"></div>
  <script>
    function play(stage) {
      const fx = { id: 45, mode: "s_wave" };
      const timers = [], rafs = [], anims = [], listeners = [];
      const regTimer = (t) => { timers.push(t); return t; };
      const regRaf = (r) => { rafs.push(r); return r; };
      const regAnim = (a) => { anims.push(a); return a; };
      const regListen = (el, ev, fn) => { el.addEventListener(ev, fn); listeners.push([el, ev, fn]); };
      const accent = '#ff5e1a', white = '#f3f4f6', muted = '#a1a8b3', surface = '#1e2129';
      const svgEl = (tag, attrs = {}) => {
        const el = document.createElementNS('http://www.w3.org/2000/svg', tag);
        Object.entries(attrs).forEach(([k, v]) => el.setAttribute(k, v));
        return el;
      };
      switch (fx.mode) {
    case 's_wave': {
              const svg = svgEl('svg', { viewBox: '0 0 240 110', width: '240', height: '110' });
              const p = svgEl('path', { fill: 'rgba(255,94,26,0.22)', stroke: accent, 'stroke-width': '2.5' });
              svg.appendChild(p);
              stage.appendChild(svg);
              const start = performance.now();
              const tick = (now) => {
                const t = (now - start) / 380;
                const y1 = 55 + Math.sin(t) * 24;
                const y2 = 55 + Math.cos(t) * 24;
                p.setAttribute('d', `M0,55 Q60,${y1.toFixed(1)} 120,55 T240,55 L240,110 L0,110 Z`);
                regRaf(requestAnimationFrame(tick));
              };
              regRaf(requestAnimationFrame(tick));
              break;
            }
      }
      return () => {
        timers.forEach(clearTimeout);
        rafs.forEach(cancelAnimationFrame);
        anims.forEach(a => { try { a.cancel(); } catch (_) {} });
        listeners.forEach(([el, ev, fn]) => el.removeEventListener(ev, fn));
      };
    }
    
    const MS = 0, PAUSE = 1500; // MS = 0: the effect already runs continuously
    const host = document.getElementById('stage');
    const still = matchMedia('(prefers-reduced-motion: reduce)').matches;
    let stop = null, timer = null, shown = false;
    function run() { if (stop) stop(); host.innerHTML = ""; stop = play(host); }
    function loop() { run(); if (!still && MS) 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>

قوالب مشابهة