الكود الكامل (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>مسار على الخريطة ودبوس يتحرك — Route Map Moving Pin</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 .rmp{position:relative;width:250px;height:150px;background:#12141a;border-radius:10px;overflow:hidden}.fxn .rmp svg{position:absolute;inset:0;width:100%;height:100%}.fxn .rmp .gr path{fill:none;stroke:#222630;stroke-width:6}.fxn .rmp .r0{fill:none;stroke:#2a2e38;stroke-width:4}.fxn .rmp .r1{fill:none;stroke:#ff5e1a;stroke-width:4;stroke-dasharray:1;stroke-dashoffset:1;stroke-linecap:round}.fxn .rmp .s{fill:#fff}.fxn .rmp .e{fill:none;stroke:#ff5e1a;stroke-width:3}.fxn .rmp .pin{position:absolute;left:0;top:0;width:14px;height:14px;margin:-7px 0 0 -7px;border-radius:50%;background:#ff5e1a;box-shadow:0 0 0 4px rgba(255,94,26,.3);offset-path:path('M20 120C60 20 110 140 150 70S220 30 230 90');offset-rotate:0deg}.fxn .rmp .ed{fill:none;stroke:#f3f4f6;stroke-width:2;stroke-dasharray:4 4;opacity:.7}.fxn .rmp .dv{fill:#12141a;stroke:#ff5e1a;stroke-width:2.5}.fxn .rmp .ot{fill:#f3f4f6}.fxn .rmp .lb text{font:700 9px Cairo,system-ui,sans-serif;fill:#f3f4f6}
</style>
</head>
<body>
<div id="stage"><div class="fxn"><div class="rmp"><svg viewBox="0 0 250 150"><g class="gr"><path d="M0 40H250M0 90H250M0 130H250M50 0V150M120 0V150M190 0V150"/></g><path class="r0" d="M20 120C60 20 110 140 150 70S220 30 230 90"/><path class="r1" d="M20 120C60 20 110 140 150 70S220 30 230 90" pathLength="1"/><circle cx="20" cy="120" r="6" class="s"/><circle cx="230" cy="90" r="7" class="e"/><path class="ed" d="M150 70L126 24"/><circle class="dv" cx="150" cy="70" r="4"/><circle class="ot" cx="45" cy="83" r="3.5"/><g class="lb"><text x="9" y="139" data-k="montreal"></text><text x="6" y="76" data-k="ottawa"></text><text x="150" y="110" text-anchor="middle" data-k="diversion"></text><text x="126" y="17" text-anchor="middle" data-k="edmonton"></text><text x="246" y="110" text-anchor="end" data-k="gimli"></text></g></svg><div class="pin"></div></div></div></div>
<script>
function play(root){
const q=s=>root.querySelector(s),qa=s=>[...root.querySelectorAll(s)],T=[],A=[],F=[];
const R=matchMedia('(prefers-reduced-motion: reduce)').matches;
const at=(ms,f)=>{T.push(setTimeout(f,R?0:ms))};
const an=(e,k,o={})=>{const a=e.animate(k,{duration:600,fill:'both',easing:'cubic-bezier(.16,1,.3,1)',...o});if(R){try{a.finish()}catch(_){}}A.push(a);return a};
const raf=f=>{let id,on=true;const l=t=>{if(!on)return;f(t);if(!R)id=requestAnimationFrame(l)};id=requestAnimationFrame(l);F.push(()=>{on=false;cancelAnimationFrame(id)})};
const tween=(dur,delay,fn)=>{at(delay,()=>{const t0=performance.now();let on=true,id;const l=now=>{if(!on)return;const p=R?1:Math.min(1,(now-t0)/dur);fn(1-Math.pow(1-p,3));if(p<1)id=requestAnimationFrame(l)};id=requestAnimationFrame(l);F.push(()=>{on=false;cancelAnimationFrame(id)})})};
const CITIES={montreal:'Montreal',ottawa:'Ottawa',diversion:'Diversion point',edmonton:'Edmonton',gimli:'Gimli'}; /* edit the city names here */
qa('.rmp .lb text').forEach(t=>{t.textContent=CITIES[t.dataset.k]||''});
an(q('.rmp .lb'),[{opacity:0},{opacity:1}],{duration:600,delay:0});
an(q('.rmp .r1'),[{strokeDashoffset:1},{strokeDashoffset:0}],{duration:4200,delay:300,easing:'cubic-bezier(.4,0,.2,1)'});an(q('.rmp .pin'),[{offsetDistance:'0%'},{offsetDistance:'100%'}],{duration:4200,delay:300,easing:'cubic-bezier(.4,0,.2,1)'});
return()=>{T.forEach(clearTimeout);A.forEach(a=>a.cancel());F.forEach(f=>f())};
}
const MS = 5600, 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>