$(document).ready(function () { // Intersection Observer¸¦ »ç¿ëÇÏ¿© .typing ¿ä¼Ò°¡ È­¸é¿¡ º¸ÀÏ ¶§ ¾Ö´Ï¸ÞÀÌ¼Ç ½ÃÀÛ const observerOptions = { root: null, // ºäÆ÷Æ® (ºê¶ó¿ìÀú â) rootMargin: "0px", threshold: 0.5 // ¿ä¼Ò°¡ 50% º¸ÀÌ¸é ½ÇÇà }; //////////////////////// Ä¿¼­ À̵¿ //////////////////////// const cursor = document.querySelector("#cursor"); let mouseX = 0, mouseY = 0; let cursorX = 0, cursorY = 0; document.addEventListener("mousemove", (e) => { mouseX = e.clientX; mouseY = e.clientY; }); function animateCursor() { const speed = 0.01; cursorX += (mouseX - cursorX) * speed; cursorY += (mouseY - cursorY) * speed; cursor.style.transform = `translate(${cursorX}px, ${cursorY}px)`; requestAnimationFrame(animateCursor); } animateCursor(); //////////////////////// date-text ¼Ó¼º ¾È¿¡ µ¿ÀÏÇÑ ÅØ½ºÆ® ³Ö±â //////////////////////// $('.main_top .colorFill').each(function () { var textContent = $(this).text().trim(); $(this).attr('data-text', textContent); }); //////////////////////// ŸÀÌÇÎ À̺¥Æ® //////////////////////// const typingTexts = { 'typingMainVs': ["¿¡ÀÌÀü½Ã", "ÄÁ¼³ÅÏÆ®"], // typing1¿¡ ÇØ´çÇÏ´Â ÅØ½ºÆ® ¹è¿­ 'typingAboutTop': ["DEVELOPER"] // typing2¿¡ ÇØ´çÇÏ´Â ÅØ½ºÆ® ¹è¿­ }; // °¢ .typing Ŭ·¡½º¸¦ °¡Áø ¿ä¼Ò¸¶´Ù º°µµÀÇ ¾Ö´Ï¸ÞÀÌ¼Ç Àû¿ë $('.typing').each(function () { const typingClass = $(this).attr('class').split(' ').find(className => typingTexts[className]); if (!typingClass) return; // ÅØ½ºÆ® ¹è¿­ÀÌ ¾øÀ¸¸é ³Ñ¾î°¨ const texts = typingTexts[typingClass]; // ÇØ´ç Ŭ·¡½º¿¡ ´ëÇÑ ÅØ½ºÆ® ¹è¿­ let currentTextIndex = 0; let currentCharIndex = 0; let isDeleting = false; let isWaitingForNextText = false; const typingElement = $(this); // ÇöÀç .typing ¿ä¼Ò ¼±Åà let observer; // ŸÀÌÇÎ È¿°ú ½ÇÇà ÇÔ¼ö function typeEffect() { const currentText = texts[currentTextIndex]; let visibleText; if (isWaitingForNextText) { // »õ ÅØ½ºÆ®°¡ ŸÀÌÇεDZâ Àü¿¡ Àá±ñ ´ë±â setTimeout(() => { isWaitingForNextText = false; isDeleting = false; // »èÁ¦ »óÅÂ ÇØÁ¦ currentCharIndex = 0; // »õ·Î¿î ÅØ½ºÆ®ºÎÅÍ ½ÃÀÛ typeEffect(); // »õ ÅØ½ºÆ® ŸÀÌÇÎ ½ÃÀÛ }, 500); // 0.5ÃÊ ´ë±â ÈÄ Å¸ÀÌÇÎ ½ÃÀÛ return; } if (isDeleting) { visibleText = currentText.slice(0, currentCharIndex--); // ±ÛÀÚ »èÁ¦ } else { if (currentCharIndex === 0) { typingElement.text(''); // »õ·Î¿î ÅØ½ºÆ® ½ÃÀÛ Àü¿¡ ³»¿ë ºñ¿ì±â } visibleText = currentText.slice(0, currentCharIndex++); // ±ÛÀÚ Ãß°¡ } typingElement.text(visibleText); if (!isDeleting && currentCharIndex === currentText.length) { setTimeout(() => { if (currentTextIndex === texts.length - 1) { // ¸¶Áö¸· ÅØ½ºÆ®¿¡¼­´Â ¸ØÃß±â (µðº§·ÎÆÛó·³ ´ÜÀÏ ÅØ½ºÆ®ÀÎ °æ¿ì) return; } isDeleting = true; }, 500); } if (isDeleting && currentCharIndex < 0) { isWaitingForNextText = true; // »õ ÅØ½ºÆ® ŸÀÌÇÎ Àü¿¡ ´ë±â currentTextIndex = (currentTextIndex + 1) % texts.length; // ´ÙÀ½ ÅØ½ºÆ®·Î À̵¿ } const speed = isDeleting ? 100 : 150; setTimeout(typeEffect, speed); } // Intersection Observer Äݹé ÇÔ¼ö function observerCallback(entries) { entries.forEach(entry => { if (entry.isIntersecting) { // È­¸é¿¡ º¸ÀÏ ¶§ ŸÀÌÇÎ ¾Ö´Ï¸ÞÀÌ¼Ç ½ÃÀÛ typeEffect(); observer.unobserve(entry.target); // ÇÑ ¹ø¸¸ ½ÇÇàµÇµµ·Ï °¨Áö ÈÄ Á¦°Å } }); } // Intersection Observer ÀνºÅϽº »ý¼º observer = new IntersectionObserver(observerCallback, observerOptions); // .typing ¿ä¼Ò°¡ È­¸é¿¡ º¸ÀÏ ¶§ ¾Ö´Ï¸ÞÀÌ¼Ç ½ÃÀÛ observer.observe(typingElement[0]); }); });