Animations/Scroll Arcs

Scroll Arcs

Arcs concentriques SVG qui tournent en fonction du scroll. Style dashboard/monitoring.

scrollSVGJSdashboard
Trigger: Scroll (rAF)
CSS requis: Non
Difficulte: hard

Preview live

Code

"use client";
import { useEffect, useRef, useState } from "react";

export default function ScrollArcs() {
  const ref = useRef<HTMLDivElement>(null);
  const [rotation, setRotation] = useState(0);

  useEffect(() => {
    let raf: number;
    const loop = () => {
      const el = ref.current;
      if (el) {
        const rect = el.getBoundingClientRect();
        const progress = Math.max(0, Math.min(1,
          (window.innerHeight - rect.top) / (window.innerHeight + rect.height)
        ));
        setRotation(progress * 360);
      }
      raf = requestAnimationFrame(loop);
    };
    raf = requestAnimationFrame(loop);
    return () => cancelAnimationFrame(raf);
  }, []);

  // Chaque arc SVG avec son propre speed multiplier
  return (
    <svg viewBox="0 0 300 300">
      {arcs.map((arc, i) => (
        <path key={i}
          d={describeArc(150, 150, arc.radius, arc.startAngle + rotation * arc.speed, arc.startAngle + rotation * arc.speed + arc.arcLength)}
          stroke={arc.color} strokeWidth={arc.strokeWidth}
          fill="none" strokeLinecap="round" />
      ))}
    </svg>
  );
}

Instructions

L'animation est pilotee par le scroll via requestAnimationFrame. Chaque arc a un speed multiplier positif ou negatif pour tourner dans des directions differentes. Ajoutez des cercles de fond subtils pour l'effet dashboard.