forked from livebloggerofficial/Logos-Showcase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
42 lines (33 loc) · 1.01 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const track = document.querySelector("#track");
const logoSlide = track.querySelector(".logo-slide");
// Clone the logo slide multiple times
for (let i = 0; i < 4; i++) {
track.appendChild(logoSlide.cloneNode(true));
}
let scrollPosition = 0;
const speed = 1;
let isPlaying = true;
let animationFrameId = null;
function scroll() {
if (!isPlaying) return; // Stop if paused
scrollPosition -= speed;
const slideWidth = logoSlide.offsetWidth;
if (Math.abs(scrollPosition) >= slideWidth) {
scrollPosition += slideWidth;
}
track.style.transform = `translateX(${scrollPosition}px)`;
animationFrameId = requestAnimationFrame(scroll);
}
// Updated hover handlers
track.addEventListener("mouseenter", () => {
isPlaying = false;
if (animationFrameId) {
cancelAnimationFrame(animationFrameId);
}
});
track.addEventListener("mouseleave", () => {
isPlaying = true;
scroll(); // Restart the animation
});
// Start the animation
scroll();