/* if ('scrollRestoration' in history) { try { history.scrollRestoration = 'manual'; } catch(e) { } } window.addEventListener('pageshow', function(e) { window.scrollTo(0, 0); setTimeout(function(){ window.scrollTo(0,0); }, 50); }); window.addEventListener('load', function() { window.scrollTo(0, 0); setTimeout(function(){ window.scrollTo(0,0); }, 50); }); */ if (history.scrollRestoration) { history.scrollRestoration = 'manual'; } function setVh() { const vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', `${vh}px`); } setVh(); window.addEventListener('resize', setVh); $(function() { $(document).ready(function() { // 2. 페이지 로드 시 스크롤을 맨 위로 보내고 AOS 시작 window.scrollTo(0, 0); AOS.init({ duration: 1000, once: false, // 스크롤 시 반복 재생 원할 경우 //disable: function() { // return window.innerWidth < 1024; // 요청하신 1024px 기준 //} }); //툴팁 /* $('.tooltip').tooltipster({ theme: 'tooltipster-default', animation: 'fade' }); */ //커서 if ($('.sub-visual').length > 0) { const mq = window.matchMedia("(min-width: 1024px)"); const cursor = document.querySelector(".cursor"); let mouse = { x: -100, y: -100 }; let pos = { x: 0, y: 0 }; const speed = 0.1; let rafId = null; let isActive = false; const updateCoordinates = (e) => { mouse.x = e.clientX; mouse.y = e.clientY; }; const updatePosition = () => { pos.x += (mouse.x - pos.x) * speed; pos.y += (mouse.y - pos.y) * speed; cursor.style.transform = `translate3d(${pos.x}px, ${pos.y}px, 0)`; }; const loop = () => { updatePosition(); rafId = requestAnimationFrame(loop); }; function initCursor() { if (isActive) return; isActive = true; window.addEventListener("mousemove", updateCoordinates); rafId = requestAnimationFrame(loop); document.querySelectorAll("[cursor-class]").forEach(el => { el.addEventListener("mouseenter", onEnter); el.addEventListener("mouseleave", onLeave); }); cursor.style.display = "block"; } function destroyCursor() { if (!isActive) return; isActive = false; window.removeEventListener("mousemove", updateCoordinates); cancelAnimationFrame(rafId); document.querySelectorAll("[cursor-class]").forEach(el => { el.removeEventListener("mouseenter", onEnter); el.removeEventListener("mouseleave", onLeave); }); cursor.style.display = "none"; } function onEnter() { cursor.classList.add(this.getAttribute("cursor-class")); } function onLeave() { cursor.classList.remove(this.getAttribute("cursor-class")); } function handleResize(e) { if (e.matches) { initCursor(); // PC } else { destroyCursor(); // 모바일 } } // 최초 실행 handleResize(mq); // resize 감지 mq.addEventListener("change", handleResize); } //텍스트 색상 변환 if ($('.effect').length > 0) { gsap.registerPlugin(ScrollTrigger); const textElements = gsap.utils.toArray('.effect'); textElements.forEach(text => { gsap.to(text, { backgroundSize: '100%', ease: 'none', scrollTrigger: { trigger: text, start: 'center 50%', end: 'center 50%', scrub: true, }, }); }); } // 상단 언어 오버시 const $links = $(".gnb-wrap .language a"); $links.on("mouseenter", function () { $links.removeClass("active"); $(this).addClass("active"); }); $(".gnb-wrap .language").on("mouseleave", function () { $links.removeClass("active"); // current 복구 $links.filter(".current").addClass("active"); }); // 초기 진입 시 current 활성화 $links.filter(".current").addClass("active"); //gnb /* var $gnb = $('.gnb'); var $gnbBg = $('.header-wrap .gnb-bg'); var $gnbItems = $('.gnb > ul > li'); var $gnbLists = $('.gnb > ul > li > ul'); var $headerWrap = $('.header-wrap '); var $current = $('.gnb > ul > li.current'); if ($current.length) $current.addClass('active'); function measureHiddenHeight($el, displayType) { displayType = displayType || 'flex'; if ($el.css('display') !== 'none') { return $el.outerHeight(); } var old = { display: $el.css('display'), position: $el.css('position'), visibility: $el.css('visibility'), left: $el.css('left'), height: $el.css('height') }; $el.css({ position: 'absolute', visibility: 'hidden', left: '-9999px', display: displayType, height: 'auto' }); var h = $el.outerHeight(); $el.css(old); return h; } var maxHeight = 0; function computeMaxHeight() { if (!$gnbLists.length) { maxHeight = 0; return; } var heights = $gnbLists.map(function() { return measureHiddenHeight($(this), 'flex'); }).get(); maxHeight = Math.max.apply(null, heights); if ($gnbBg.length) { $gnbBg.css({ //height: '0px', transition: 'height 0.2s ease', overflow: 'hidden' }); } $gnbLists.each(function() { $(this).css({ overflow: 'hidden', display: 'none', //height: '0px', transition: 'height 0.2s ease' }); }); } computeMaxHeight(); $(window).on('load resize', computeMaxHeight); function showMenu() { $headerWrap.addClass('active'); $gnbItems.removeClass('active'); if ($gnbBg.length) $gnbBg.css('height', maxHeight + 'px'); $gnbLists.each(function() { $(this).css('display', 'flex'); $(this).outerHeight(); // force reflow $(this).css('height', maxHeight + 'px'); }); } function hideMenu() { $headerWrap.removeClass('active'); $gnbItems.removeClass('active'); if ($current.length) $current.addClass('active'); if ($gnbBg.length) $gnbBg.css('height', '0px'); $gnbLists.each(function() { var $ul = $(this); $ul.css('height', '0px'); $(this).css('display', 'none'); // $ul.one('transitionend', function(e) { // if (e.originalEvent.propertyName === 'height') { // $ul.css('display', 'none'); // } // }); }); } if ($gnb.length && $gnbBg.length) { $gnb.on('mouseenter focusin', showMenu) .on('mouseleave focusout', hideMenu); $gnbBg.on('mouseenter', showMenu) .on('mouseleave focusout', hideMenu); } */ var gnbheight = 0; // 높이를 계산하는 함수 분리 function setGnbHeight() { // 임시로 display를 보이게 해서 높이를 측정해야 할 수도 있습니다. // 하지만 보통 1024 이상에서만 실행되도록 조건문을 거는 것이 안전합니다. if ($(window).width() >= 1024) { // 기존 높이 초기화 후 재측정 $(".gnb-wrap .gnb > ul > li > ul").css("display", "flex"); gnbheight = Math.max.apply(null, $(".gnb-wrap .gnb > ul > li > ul").map(function() { return $(this).outerHeight(); }).get() ); // 측정 후 다시 숨김 (이벤트 발생 전까지) $(".gnb-wrap .gnb > ul > li > ul").css("display", "none"); } } // 초기 실행 setGnbHeight(); // 윈도우 리사이즈 시 높이 다시 계산 (디바운싱 적용 권장) $(window).on('resize', function() { setGnbHeight(); }); $(".gnb-wrap .gnb > ul > li.current").addClass('active'); $(".header-wrap .gnb-bg").css("height", 0); $('.gnb-wrap .gnb, .header-wrap .gnb-bg').on({ 'mouseenter focus': function () { if ($(window).width() >= 1024) { // PC 모드에서만 동작 $('.header-wrap').addClass('active'); $('.gnb-wrap .gnb > ul > li').removeClass('active'); $(".header-wrap .gnb-bg").css("height", gnbheight); $(".gnb-wrap .gnb > ul > li > ul").css({ "display": "flex", "height": gnbheight }); } }, 'mouseleave blur': function () { if ($(window).width() >= 1024) { $('.header-wrap').removeClass('active'); $('.gnb-wrap .gnb > ul > li').removeClass('active'); $('.gnb-wrap .gnb > ul > li.current').addClass('active'); $(".header-wrap .gnb-bg").css("height", 0); $(".gnb-wrap .gnb > ul > li > ul").css({ "display": "none", "height": 0 }); } }, }); //gnb(topmenu) 겹침 현상 방지 코드 $('.gnb-wrap').addClass('loaded'); // aside 서브메뉴 if ($('.aside').length > 0) { let isMobile = null; function bindAsideEvent() { const nowMobile = $(window).width() < 1014; // PC <-> 모바일 전환 시에만 처리하도록 if (isMobile !== nowMobile) { // 기존 이벤트 제거 $('.aside dt a').off('click'); $('.aside').off('mouseleave'); if (nowMobile) { // ★ 모바일 진입 시 무조건 메뉴 닫기 $(".aside dd").hide(); // 모바일 동작 $('.aside dt a').on('click', function (e) { e.preventDefault(); $('.aside dd').toggle(); }); $('.aside').on('mouseleave', function () { $('.aside dd').hide(); }); } else { // PC 동작: 항상 펼치기 $(".aside dd").css("display", "block"); } // 현재 상태 저장 isMobile = nowMobile; } } // 최초 실행 bindAsideEvent(); // 리사이즈 이벤트 $(window).on('resize', function () { bindAsideEvent(); }); } //사이드바 $('.btn-sidebar, #btn-sidebar').click(function(){ if ($('body').hasClass('sidebar-opened')) { $('body').removeClass('sidebar-opened'); } else { $('body').addClass('sidebar-opened'); } return false; }); $('.sidebar-backdrop').click(function(){ $('body').removeClass('sidebar-opened'); return false; }); //헤더 고정 if ($('.header-wrap').length > 0) { function toggleHeaderFixed() { var headerH = 0; var scrollTop = $(window).scrollTop(); if (scrollTop > headerH) { $('.wrap').addClass('body-fixed'); } else { $('.wrap').removeClass('body-fixed'); } } $(window).scroll(toggleHeaderFixed); $(document).ready(toggleHeaderFixed); toggleHeaderFixed(); } //sub-visual if ($('.sub-visual').length > 0) { function toggleSubFixed() { var headerH = $(".header-wrap").outerHeight() || 0; var naviH = $(".sub-visual .navi").outerHeight() || 0; var asideH = $(".sub-visual .aside").outerHeight() || 0; var fixedPoint = headerH + naviH; var scrollTop = $(window).scrollTop(); if (scrollTop > naviH) { $(".sub-visual").addClass("aside-fixed"); $(".aside-fixed .titleText").css("margin-top", asideH); } else { $(".sub-visual .titleText").css("margin-top", "0"); $(".sub-visual").removeClass("aside-fixed"); } } $(window).on("scroll", toggleSubFixed); $(window).on("resize", toggleSubFixed); toggleSubFixed(); } if ($('.full-visual').length > 0) { function toggleSubTop() { var headerH = $(".header-wrap").outerHeight() || 0; var asideH = $(".sub-visual .aside").outerHeight() || 0; var TopH = $(window).height() - asideH; TopH = Math.max(0, TopH); // 음수 방지 $(".sub-container").css("margin-top", TopH + "px"); } $(window).on("resize", toggleSubTop); toggleSubTop(); } if ($('.sub-title').length > 0) { function toggleTitleTop() { var titleH = $(".sub-title").outerHeight() || 0; var TopH = titleH * 0.9; $(".sub-title").css("top", -TopH); } $(window).on("resize", toggleTitleTop); toggleTitleTop(); } if ($('.greeting').length > 0) { function fitTextToDiv(box) { const text = box.querySelector('.greeting .title .fit-text'); const boxWidth = box.clientWidth; let fontSize = 180; // 시작 크기 text.style.fontSize = fontSize + 'px'; while (text.scrollWidth > boxWidth && fontSize > 5) { fontSize--; text.style.fontSize = fontSize + 'px'; } } document.querySelectorAll('.greeting .title').forEach(fitTextToDiv); window.addEventListener('resize', () => { document.querySelectorAll('.greeting .title').forEach(fitTextToDiv); }); } //business if ($('.business-wrap').length > 0) { // tab 헤더고정 function toggleTabFixed() { var scrollTop = $(window).scrollTop(); var bodyH = $("body").outerHeight() || 0; var headerH = $(".gnb-wrap").outerHeight() || 0; var tabH = $(".tab-nav").outerHeight() || 0; var subH = $(".sub-visual").outerHeight() || 0; var graphicH = $(".graphic-wrap").outerHeight() || 0; var listH = $(".business-wrap .business-list.active").outerHeight() || 0; var paddingTop = parseInt($('.business-wrap .content-wrap').css('padding-top')) || 0; //var thumbH = $('.business-wrap .thumb-box').outerHeight() || 0; if (window.matchMedia("(min-width: 1024px)").matches) { $(".business-list .thumb-list").css("height", bodyH - (headerH + tabH)); $(".business-list .sticky-wrap").css("top", headerH + tabH); $(".business-list .sticky-wrap").css("min-height", bodyH - (headerH + tabH)); //$('.business-wrap .tab-nav').addClass('tab-fixed'); //$(".business-list .text-list").css("top", headerH + tabH); //$(".business-list .text-box").css("min-height", bodyH - (headerH + tabH)); if (scrollTop > graphicH + listH - tabH) { $('.tab-nav').css("opacity", "0"); } else { $('.tab-nav').css("opacity", "1"); } } else { $(".business-list .thumb-list").css("min-height", "auto"); $(".business-list .sticky-wrap").css("top", 0); $(".business-list .sticky-wrap").css("height", "auto"); //$(".business-list .text-list").css("top", 0); //$(".business-list .text-box").css("min-height", "auto"); } if (scrollTop > subH + graphicH) { $(".business-wrap .contents").addClass("active"); } else { $(".business-wrap .contents").removeClass("active"); } } $(document).ready(toggleTabFixed); $(window).scroll(toggleTabFixed); $(window).on("resize", toggleTabFixed); toggleTabFixed(); const pathParts = window.location.pathname.split("/").filter(Boolean); // business 값 가져오기 const business = parseInt(pathParts[pathParts.length - 1], 10); if (!isNaN(business)) { $(".business-list").removeClass("active"); $("#business" + business).addClass("active"); } // tab-nav 메뉴 클릭 시 이동 $(".tab-nav li a").on("click", function(e) { e.preventDefault(); // 기본 링크 이동 막기 const index = ($(this).parent().index() + 1) * 10; // li index const target1 = $("#business" + index); const target2 = $("#business" + index + " .thumb-wrap .thumb-box:first-child"); const target3 = $(".business-wrap .contents"); //var tabH = $(".tab-nav").outerHeight() || 0; var paddingTop = parseInt($('.business-wrap .content-wrap').css('padding-top')) || 0; // 콘텐츠 활성화 처리 $(".business-list").removeClass("active"); target1.addClass("active"); target2.css("opacity", "1"); // tab-nav active 클래스 변경 $(".tab-nav li").removeClass("active"); $(this).parent().addClass("active"); const index2 = $(this).parent().index(); const gnbBusiness = $(".gnb > ul > li:nth-child(2) ul li"); gnbBusiness.removeClass("current"); gnbBusiness.eq(index2).addClass("current"); function getHeaderHeight() { return window.matchMedia("(min-width: 1024px)").matches ? 0 : document.querySelector(".body-fixed .gnb-wrap")?.offsetHeight || 0; } const scrollToTarget = () => { window.scrollTo({ top: target3.offset().top + paddingTop - getHeaderHeight(), behavior: "smooth" }); }; scrollToTarget(); history.replaceState(null, "", `/business/${index}${location.search}`); // 탭 전환 후 요소가 보여지는 시점에 AOS 갱신 setTimeout(function() { AOS.refresh(); // AOS 위치 값 재계산 }, 200); // 탭이 완전히 전환된 후 실행되도록 약간의 지연시간을 둠 }); const sections = document.querySelectorAll( ".business-list .text-list .text-box" ); const catelist = document.querySelectorAll(".cate-list a"); const observer = new IntersectionObserver( (entries) => { entries.forEach(entry => { if (!entry.isIntersecting) return; const id = entry.target.getAttribute("data-anchor-id") || entry.target.id; if (!id) return; // 모든 active 제거 catelist.forEach(a => a.classList.remove("active")); // data-target 기준으로 활성화 const targetLink = document.querySelector( `.cate-list a[data-target="${id}"]` ); if (targetLink) { targetLink.classList.add("active"); } }); }, { root: null, threshold: 0.5 } ); sections.forEach(el => observer.observe(el)); // 탭 전환 후 요소가 보여지는 시점에 AOS 갱신 setTimeout(function() { //if (window.innerWidth >= 1024) { AOS.refresh(); // AOS 위치 값 재계산 //} }, 200); // 탭이 완전히 전환된 후 실행되도록 약간의 지연시간을 둠 $('.business-list .cate-list a').on('click', function (e) { e.preventDefault(); e.stopPropagation(); const targetId = $(this).data('target'); const $target = $('#' + targetId); if (!$target.length) return false; // 🔥 클릭 즉시 active 처리 $('.business-list .cate-list a').removeClass('active'); $(this).addClass('active'); const headerH = $('.gnb-wrap').outerHeight() || 0; const tabH = $('.tab-nav').outerHeight() || 0; requestAnimationFrame(() => { const top = $target.offset().top - headerH - tabH; $('html, body').stop().animate({ scrollTop: top }, 200); }); return false; }); } //business1111 /* if ($('.business').length > 0) { const toSplit = document.querySelector('[data-split]'); const content = toSplit.innerText; const contentLength = content.length; const PPC = 10; const BUFFER = 40; document.documentElement.style.setProperty('--buffer', BUFFER); document.documentElement.style.setProperty('--ppc', PPC); document.documentElement.style.setProperty('--pad', 8); document.documentElement.style.setProperty('--content-length', contentLength + 2); const words = toSplit.innerText.split(' '); toSplit.innerHTML = ''; let cumulation = 10; words.forEach((word, index) => { const text = Object.assign(document.createElement('span'), { innerHTML: `${word} `, style: ` --index: ${index}; --start: ${cumulation}; --end: ${cumulation + word.length}; ` }); text.dataset.index = index; text.dataset.start = cumulation; text.dataset.end = cumulation + word.length; cumulation += word.length + 1; toSplit.appendChild(text); }); if (!CSS.supports('animation-timeline: scroll()')) { gsap.registerPlugin(ScrollTrigger); console.info('GSAP ScrollTrigger: Registered'); // Animate the words for (const word of toSplit.children) { gsap.fromTo( word, { '--active': 0 }, { '--active': 1, ease: 'steps(1)', scrollTrigger: { trigger: '.reader', start: `top top-=${word.dataset.start * PPC}`, end: `top top-=${word.dataset.end * PPC}`, scrub: true } }); } } } */ //product list if ($('.product-list').length > 0) { // AOS offset & delay 적용 함수 function setAosOffset(targetSelector) { const items = document.querySelectorAll(`${targetSelector} li[data-aos]`); const isSearchList = $(targetSelector).closest('.product-search-list-wrap').length > 0; let column = 3; // default PC (1024 ~ 1599) if (isSearchList && window.matchMedia("(min-width: 1600px)").matches) { //if (isSearchList && window.matchMedia >= 1600) { column = 4; // 1600 이상이고 검색목록일때 } else if (window.matchMedia("(max-width: 1023px)").matches) { column = 2; // 1024 미만 } items.forEach((item, index) => { const colIndex = index % column; // 0 ~ column-1 const offsetValue = colIndex * 150; // 150px씩 증가 item.setAttribute("data-aos-delay", offsetValue); }); } // 초기 실행 setAosOffset(".product-list"); //setAosOffset(".product-search-list-wrap .product-list"); // 화면 리사이즈 시 재계산 window.addEventListener("resize", () => { setAosOffset(".product-list"); //setAosOffset(".product-search-list-wrap .product-list"); }); } //history if ($('.history').length > 0) { // 요소의 위치를 가져오는 함수 function getOffsets() { var offsets = { quick: $('.history').offset().top, }; return offsets; } // 클래스를 토글하는 함수 function toggleClass(selector, condition, className) { if (condition) { $(selector).addClass(className); } else { $(selector).removeClass(className); } } // 스크롤 및 리사이즈 이벤트 처리 함수 function handleScrollAndResize() { var offsets = getOffsets(); var scrollTop = $(window).scrollTop(); var windowHeight = $(window).height(); // 현재 .year 중 다른 요소에 is-active가 있는지 체크 var hasActiveOther = $('.history .year-list .year:not(:first-child)').hasClass('is-active'); // 조건: 스크롤 위치 & 다른 요소가 active가 아닐 때 if (scrollTop + windowHeight > offsets.quick && !hasActiveOther) { $('.history .year-list .year:first-child').addClass('is-active'); } else { $('.history .year-list .year:first-child').removeClass('is-active'); } } // 스크롤 및 리사이즈 이벤트 리스너 등록 $(window).on('scroll resize', handleScrollAndResize); // 초기 로드시 이미 화면에 요소가 있는지 확인 $(document).ready(function() { handleScrollAndResize(); }); } }); });