را نیاز دارد؛ بقیه فایل برای تست هم هست -->
/*
JS برای:
1) کپی خودکار محتوا تا یک لوپ پیوسته ایجاد شود (بدون پرش)
2) فعالسازی انیمیشن با توجه به طول واقعی محتوا
3) تضمین رفتار در حالت تغییر اندازه (resize)
*/
(function(){
const track = document.getElementById('scrollerTrack');
if(!track) return;
// clone contents to make seamless loop
const clone = track.cloneNode(true);
clone.setAttribute('aria-hidden', 'true'); // cloned content isn't announced
track.parentNode.appendChild(clone);
// wrap both tracks in a container so we can animate full width
// (in our HTML we already used a single .logo-scroller container,
// but we rely on duplicated inline content: initial track + clone)
// calculate widths and set animation-duration adaptively if wanted
// add class to start animation (so CSS loads first)
function startAnimation(){
// ensure combined width is > viewport to avoid weirdness
requestAnimationFrame(()=>{
// (optional) compute required duration based on content width:
// keep default unless you want speed proportional to width.
track.classList.add('animating');
clone.classList.add('animating');
});
}
// Pause animation while user touches/pressing for better UX on mobile
['touchstart','pointerdown'].forEach(e=>{
track.parentNode.addEventListener(e, ()=> {
track.style.animationPlayState = 'paused';
clone.style.animationPlayState = 'paused';
}, {passive:true});
});
['touchend','pointerup','pointercancel','mouseleave'].forEach(e=>{
track.parentNode.addEventListener(e, ()=> {
track.style.animationPlayState = '';
clone.style.animationPlayState = '';
}, {passive:true});
});
// ensure there are at least two sets (we already appended one clone)
// but if the content is still too narrow compared to viewport, add more clones
function ensureEnoughContent(){
const parent = track.parentNode;
const totalWidth = Array.from(parent.children).reduce((sum, el)=>{
return sum + el.getBoundingClientRect().width;
}, 0);
const viewport = parent.getBoundingClientRect().width;
// if total width < 2 * viewport, duplicate again
let attempts = 0;
while(totalWidth < 2 * viewport && attempts {
clearTimeout(rTimer);
rTimer = setTimeout(()=> {
// remove animating class briefly to allow layout recalculation
track.classList.remove('animating');
clone.classList.remove('animating');
ensureEnoughContent();
startAnimation();
}, 120);
});
})();