1document.addEventListener("DOMContentLoaded", () => { 2 const scroller = document.querySelector(".recent-big-wins-scroller__cards"); 3 if (!scroller) return; 4 5 let timer = null; 6 let index = 0; 7 let step = 0; 8 let originalCount = 0; 9 let cloneCount = 0; 10 let prefersReduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches; 11 12 function getStep(cards) { 13 if (cards.length >= 2) { 14 // РазниÑа левÑÑ Ð¿Ð¾Ð·Ð¸Ñий надÑжнее лÑбÑÑ margin/gap 15 const left0 = cards[0].offsetLeft; 16 const left1 = cards[1].offsetLeft; 17 const delta = left1 - left0; 18 if (delta > 0) return delta; 19 } 20 // Фоллбек: ÑиÑина + пÑавÑй margin 21 const cs = getComputedStyle(cards[0]); 22 const mr = parseFloat(cs.marginRight || "0") || 0; 23 return cards[0].offsetWidth + mr; 24 } 25 26 function clearClones() { 27 scroller.querySelectorAll(".recent-big-wins-card.is-clone").forEach(n => n.remove()); 28 } 29 30 function init() { 31 // ÐÑÑановим пÑежний Ñикл и поÑиÑÑим ÐºÐ»Ð¾Ð½Ñ 32 if (timer) { clearInterval(timer); timer = null; } 33 clearClones(); 34 scroller.scrollTo({ left: 0, behavior: "auto" }); 35 index = 0; 36 37 const cards = Array.from(scroller.querySelectorAll(".recent-big-wins-card")); 38 originalCount = cards.length; 39 if (originalCount === 0) return; 40 41 // ÐоÑÑиÑаем Ñаг и ÑколÑко каÑÑоÑек помеÑаеÑÑÑ Ð²Ð¾ вÑÑпоÑÑе 42 step = getStep(cards); 43 const visible = Math.max(1, Math.floor(scroller.clientWidth / step)); 44 45 // ÐÑли ÑкÑоллиÑÑ Ð½ÐµÑего â пÑоÑÑо вÑÑ Ð¾Ð´Ð¸Ð¼ 46 const totalWidth = cards[cards.length - 1].offsetLeft + cards[cards.length - 1].offsetWidth - cards[0].offsetLeft; 47 if (totalWidth <= scroller.clientWidth + 1) return; 48 49 // ÐлониÑÑем пеÑвÑе N каÑÑоÑек (на 1 болÑÑе видимого, ÑÑÐ¾Ð±Ñ Ñов бÑл невидим) 50 cloneCount = Math.min(originalCount, visible + 1); 51 for (let i = 0; i < cloneCount; i++) { 52 const clone = cards[i].cloneNode(true); 53 clone.classList.add("is-clone"); 54 // ЧÑÐ¾Ð±Ñ Ð½Ðµ меÑали доÑÑÑпноÑÑи 55 clone.setAttribute("aria-hidden", "true"); 56 scroller.appendChild(clone); 57 } 58 59 // ÐапÑÑкаем Ñикл 60 const intervalMs = 1500; 61 timer = setInterval(tick, intervalMs); 62 } 63 64 function tick() { 65 const behavior = prefersReduced ? "auto" : "smooth"; 66 index += 1; 67 scroller.scrollTo({ left: index * step, behavior }); 68 69 // Ðогда пеÑеÑли на пеÑвÑй клон (index === originalCount), 70 // дождÑмÑÑ Ð¾ÐºÐ¾Ð½ÑÐ°Ð½Ð¸Ñ Â«smooth» и мгновенно ÑелепоÑÑиÑÑемÑÑ Ð² наÑало. 71 if (index === originalCount) { 72 // ТаймаÑÑ ~длиÑелÑноÑÑи scroll-behavior: smooth. 350â450 Ð¼Ñ Ð¾Ð±ÑÑно доÑÑаÑоÑно. 73 const snapDelay = prefersReduced ? 0 : 420; 74 setTimeout(() => { 75 scroller.scrollTo({ left: 0, behavior: "auto" }); 76 index = 0; 77 }, snapDelay); 78 } 79 } 80 81 // ÐебаÑÐ½Ñ ÑеÑайза â пеÑеÑÑÑÑ Ñага/клонов 82 let resizeT; 83 window.addEventListener("resize", () => { 84 clearTimeout(resizeT); 85 resizeT = setTimeout(init, 150); 86 }, { passive: true }); 87 88 init(); 89});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.