document.addEventListener("DOMContentLoaded", function() { const textElements = document.querySelectorAll('.scrollingText'); function getOffsetAdjustment() { const screenWidth = window.innerWidth; if (screenWidth <= 420) { return -50; // 420px ÀÌÇÏ¿¡¼­ 30% Ãß°¡ À̵¿ } else if (screenWidth <= 800) { return -60; // 800px ÀÌÇÏ¿¡¼­ 15% Ãß°¡ À̵¿ } else if (screenWidth <= 1000) { return -70; // 1000px ÀÌÇÏ¿¡¼­ 10% Ãß°¡ À̵¿ } return -70; // ±× ¿ÜÀÇ °æ¿ì Ãß°¡ À̵¿ ¾øÀ½ } function updateTextPosition() { var windowHeight = window.innerHeight; var scrollPosition = window.pageYOffset + windowHeight / 2; // ÇöÀç ½ºÅ©·Ñ À§Ä¡ + È­¸éÀÇ Àý¹Ý textElements.forEach(textElement => { var wrapper = textElement.closest('.wrapper_f'); var wrapperTop = wrapper.getBoundingClientRect().top + window.pageYOffset; var wrapperBottom = wrapper.getBoundingClientRect().bottom + window.pageYOffset; var wrapperCenter = (wrapperTop + wrapperBottom) / 2; var maxScroll = document.body.scrollHeight - windowHeight; // ½ºÅ©·Ñ À§Ä¡°¡ wrapperÀÇ Áß¾Ó¿¡ µµ´ÞÇßÀ» ¶§ÀÇ °è»ê var scrollImpact = (scrollPosition - wrapperCenter + windowHeight / 2) / windowHeight; scrollImpact = Math.max(-1, Math.min(1, scrollImpact)); // -1°ú 1 »çÀÌ·Î Á¦ÇÑ var textPosition = (scrollImpact * 100).toFixed(2); textPosition = -textPosition - getOffsetAdjustment(); // ÅؽºÆ® À§Ä¡ ¾÷µ¥ÀÌÆ® if (textPosition < -100) textPosition = -100; if (textPosition > 100) textPosition = 100; textElement.style.left = textPosition + '%'; }); } window.addEventListener('scroll', updateTextPosition); updateTextPosition(); // Ãʱâ À§Ä¡ ¼³Á¤ function updateGradient(timestamp) { const timeFactor = (timestamp / 5000) % 1; // 5ÃÊ °£°ÝÀ¸·Î º¯È­ textElements.forEach(textElement => { const gradientColors = colors.map((color, index) => { const startColor = colors[index % colors.length]; const endColor = colors[(index + 1) % colors.length]; const factor = (timeFactor + index * 0.2) % 1; return interpolateColor(factor, startColor, endColor); }); const gradient = `linear-gradient(to left, ${gradientColors.join(', ')})`; textElement.style.background = gradient; textElement.style.webkitBackgroundClip = 'text'; textElement.style.webkitTextFillColor = 'transparent'; }); requestAnimationFrame(updateGradient); } requestAnimationFrame(updateGradient); }); // »ö»ó ¹è¿­ Á¤ÀÇ const colors = ['#0077CC', '#0099FF', '#00BBFF', '#007ea5', '#00445f']; function updateGradient(timestamp) { const textElement = document.getElementById('scrollingText'); const timeFactor = (timestamp / 5000) % 1; // 5ÃÊ °£°ÝÀ¸·Î º¯È­ const gradientColors = colors.map((color, index) => { // °¢ »ö»ó¸¶´Ù ½Ã°£ º¯È­¸¦ °í·ÁÇÏ¿© º¸°£ const startColor = colors[index % colors.length]; const endColor = colors[(index + 1) % colors.length]; const factor = (timeFactor + index * 0.2) % 1; // °¢ »ö»ó¿¡ ´ëÇÑ ¿ÀÇÁ¼Â return interpolateColor(factor, startColor, endColor); }); // ±×¶óµ¥ÀÌ¼Ç ½ºÆ®¸µ ±¸¼º const gradient = `linear-gradient(to left, ${gradientColors.join(', ')})`; textElement.style.background = gradient; textElement.style.webkitBackgroundClip = 'text'; textElement.style.webkitTextFillColor = 'transparent'; requestAnimationFrame(updateGradient); } requestAnimationFrame(updateGradient); // »ö»ó º¸°£ ÇÔ¼ö function interpolateColor(t, start, end) { const [r1, g1, b1] = hexToRgb(start); const [r2, g2, b2] = hexToRgb(end); const r = Math.round(r1 + (r2 - r1) * easeInOutQuad(t)); const g = Math.round(g1 + (g2 - g1) * easeInOutQuad(t)); const b = Math.round(b1 + (b2 - b1) * easeInOutQuad(t)); return `rgb(${r}, ${g}, ${b})`; } // ÀÌ¡ ÇÔ¼ö function easeInOutQuad(t) { return t < 0.5 ? 2 * t * t : 1 - Math.pow(-2 * t + 2, 2) / 2; } // 16Áø¼ö »ö»óÀ» RGB·Î º¯È¯ function hexToRgb(hex) { const r = parseInt(hex.slice(1, 3), 16); const g = parseInt(hex.slice(3, 5), 16); const b = parseInt(hex.slice(5, 7), 16); return [r, g, b]; }