// ½½¶óÀÌ´õ ¹× Trail ¿ä¼Ò const slider = document.querySelector(".slider"); const trail = document.querySelectorAll(".trail div"); // »óÅ °ü¸® º¯¼ö let tValue = 0; // Transform °ª let trailValue = 0; // Trail À妽º °ª let start; // ÀÚµ¿ Àç»ý ŸÀÌ¸Ó ID const interval = 10000; // ÀÚµ¿ Àç»ý ½Ã°£ // ¹öư ¿ä¼Ò const pauseButton = document.querySelector(".sliderPause"); const playButton = document.querySelector(".sliderPlay"); // GSAP ¾Ö´Ï¸ÞÀÌ¼Ç ¼³Á¤ const tl = gsap.timeline({ defaults: { duration: 0.6, ease: "power2.inOut" } }); tl.from(".bg", { x: "-100%", opacity: 0 }) .from(".details p", { opacity: 0 }, "-=0.2") .from(".slider h1", { opacity: 0, y: "30px" }, "-=0.9") .from(".details button", { opacity: 1, y: "10px" }, "-=0.8") .from(".illustration .inner", { opacity: 0, y: "30px" }, "-=0.9"); // ½½¶óÀ̵å À̵¿ ¹× Trail ¾÷µ¥ÀÌÆ® const moveSlide = () => { slider.style.transform = `translateX(-${tValue}%)`; trail.forEach((cur, idx) => cur.classList.toggle("active", idx === trailValue) ); }; // Trail ¾÷µ¥ÀÌÆ® ÇÔ¼ö const updateTrailValue = () => { trailValue = Math.floor(tValue / 25); // tValue¸¦ ±âÁØÀ¸·Î trailValue °è»ê }; // ½½¶óÀ̵å ÇÔ¼ö const slide = (direction) => { if (direction === "increase") { tValue = tValue === 75 ? 0 : tValue + 25; } else { tValue = tValue === 0 ? 75 : tValue - 25; } updateTrailValue(); moveSlide(); animate(); }; // ¾Ö´Ï¸ÞÀÌ¼Ç Àç½ÃÀÛ const animate = () => { tl.restart(); }; // ÀÚµ¿ Àç»ý ½ÃÀÛ const startAutoPlay = () => { clearInterval(start); // ±âÁ¸ ŸÀÌ¸Ó Á¦°Å pauseButton.style.display = "block"; playButton.style.display = "none"; start = setInterval(() => slide("increase"), interval); }; // ÀÚµ¿ Àç»ý ÁßÁö const stopAutoPlay = () => { clearInterval(start); // ŸÀÌ¸Ó ÁßÁö pauseButton.style.display = "none"; playButton.style.display = "block"; }; // Trail Ŭ¸¯ À̺¥Æ® Çڵ鷯 const onTrailClick = (e) => { stopAutoPlay(); // ÀÚµ¿ Àç»ý ÁßÁö const targetIndex = Array.from(trail).indexOf(e.target); if (targetIndex !== -1) { tValue = targetIndex * 25; updateTrailValue(); moveSlide(); animate(); } }; // ´ÙÀ½/ÀÌÀü ¹öư Ŭ¸¯ À̺¥Æ® document.querySelectorAll(".svg").forEach((button) => { button.addEventListener("click", () => { stopAutoPlay(); // ÀÚµ¿ Àç»ý ÁßÁö slide(button.classList.contains("next") ? "increase" : "decrease"); }); }); // Àç»ý/ÀϽÃÁ¤Áö ¹öư Ŭ¸¯ À̺¥Æ® pauseButton.addEventListener("click", stopAutoPlay); playButton.addEventListener("click", startAutoPlay); // Trail Ŭ¸¯ À̺¥Æ® Ãß°¡ trail.forEach((el) => el.addEventListener("click", onTrailClick)); // ÅÍÄ¡ À̺¥Æ® (() => { let startX, changeX, sliderWidth; slider.addEventListener("touchstart", (e) => { startX = e.touches[0].clientX; sliderWidth = slider.clientWidth / trail.length; }); slider.addEventListener("touchmove", (e) => { changeX = e.touches[0].clientX - startX; }); slider.addEventListener("touchend", () => { if (changeX > sliderWidth / 4) slide("decrease"); if (changeX < -sliderWidth / 4) slide("increase"); changeX = 0; }); })(); // DOMContentLoaded¿¡¼­ ÀÚµ¿ Àç»ý ½ÃÀÛ document.addEventListener("DOMContentLoaded", startAutoPlay);