$(document).ready(function () { //AOS 초기화 // AOS.init({ // duration: 800, // once: false, // offset: 100, // easing: 'ease-in-out', // }); // 스크롤시 header 효과 $(window).scroll(function () { const scroll_top = $(this).scrollTop(); if (scroll_top >= 30) { $("header").addClass("on"); } else { $("header").removeClass("on"); } }); // 게시판있는 페이지에는 스크롤효과 적용안함 window.onload = function () { const isBoardPage = window.location.href.includes('com_board'); if (isBoardPage) { return; } try { const lenis = new Lenis({ duration: 1, lerp: 0.1, smoothWheel: true, }); function raf(time) { lenis.raf(time); requestAnimationFrame(raf); } requestAnimationFrame(raf); // TOP 버튼 클릭 이벤트 $('#quick .go-top').on('click', function (e) { e.preventDefault(); lenis.scrollTo(0); }); } catch (error) { console.error('Lenis initialization failed:', error); } }; // 사이트맵 $('.menu').on('click', function (e) { e.preventDefault(); $('.sitemap, .sitemap_bg').fadeIn(300); }); $('.sitemap .top a').on('click', function (e) { e.preventDefault(); $('.sitemap, .sitemap_bg').fadeOut(300); }); $('.sitemap_bg').on('click', function () { $('.sitemap, .sitemap_bg').fadeOut(300); }); // 이미지 갤러리 클릭시 크게보임 window.addEventListener('load', function () { if (typeof GLightbox !== 'undefined') { const lightbox = GLightbox({ touchNavigation: true, loop: true, autoplayVideos: false, }); } }); // ================================= $(function () { const $nav = $('header nav'); const $hoverBg = $('.nav_hover_bg'); const $menuItems = $('header nav > ul > li'); $menuItems.on('mouseenter', function () { $menuItems.removeClass('is-active'); $(this).addClass('is-active'); const parentLeft = $nav.offset().left; const itemLeft = $(this).offset().left; const itemWidth = $(this).outerWidth(); const relativeLeft = itemLeft - parentLeft; // 1. 바가 숨겨져 있었다면 나타나게 함 if ($hoverBg.css('display') === 'none') { $hoverBg.css({ left: relativeLeft, width: itemWidth }).show(); gsap.fromTo($hoverBg, { opacity: 0 }, { opacity: 1, duration: .8 }); } // 2. 해당 위치로 부드럽게 이동 (GSAP) gsap.to($hoverBg, { left: relativeLeft, width: itemWidth, duration: 0.3, ease: "power2.out" }); }); // 헤더 전체에서 마우스가 나갈 때 바 숨기기 $('header').on('mouseleave', function () { $menuItems.removeClass('is-active'); gsap.to($hoverBg, { opacity: 0, duration: 0.2, onComplete: () => $hoverBg.hide() }); }); }); $('.subMenu').css({ height: 0, overflow: 'hidden' }); $('header').hover( function () { // 마우스 올렸을 때: 메뉴가 내려오면서 보더 생성 $(this).find('.subMenu').stop().animate({ height: '38rem' }, 300); $(this).find('.header_bg').stop().animate({ height: '38rem' }, 300, function () { $(this).css('border-bottom', '1px solid #ccc'); }); }, function () { $(this).find('.subMenu').stop().animate({ height: '0' }, 300); $(this).find('.header_bg').stop().animate({ height: '0' }, 400, function () { $(this).css('border-bottom', 'none'); }); } ); // **************************** // main visual function animateSlideText(slide, directionOut = false) { gsap.fromTo($(slide).find('.slide-text'), { opacity: 0, x: directionOut ? 0 : -50 }, { opacity: directionOut ? 0 : 1, x: directionOut ? 50 : 0, duration: directionOut ? 0.3 : 0.6, stagger: 0.15, ease: "power2.out" } ); } var swiper1 = new Swiper(".section1 .s1Swiper", { loop: true, speed: 1000, pagination: { el: ".s1Swiper .swiper-pagination", clickable: true, }, navigation: { nextEl: ".s1Swiper_arrow .swiper-button-next", prevEl: ".s1Swiper_arrow .swiper-button-prev", }, autoplay: { delay: 3000, disableOnInteraction: false, }, on: { init: function () { animateSlideText(this.slides[this.activeIndex]); }, slideChangeTransitionStart: function () { animateSlideText(this.slides[this.activeIndex], true); }, slideChangeTransitionEnd: function () { animateSlideText(this.slides[this.activeIndex]); } } }); // =============================== if (window.innerWidth >= 768) { const list = document.querySelector('.accordion_list'); if (list) { const $items = $('.accordion_list .acc_item'); let activeIndex = 0; let isPaused = false; let timer; const delay = 3000; let isDragging = false; let startX, scrollLeft; // 의료진 5명이상 시 드래그 필요 list.addEventListener('mousedown', (e) => { isDragging = true; startX = e.pageX - list.offsetLeft; scrollLeft = list.scrollLeft; list.style.cursor = 'grabbing'; isPaused = true; clearTimeout(timer); }); list.addEventListener('mousemove', (e) => { if (!isDragging) return; e.preventDefault(); const x = e.pageX - list.offsetLeft; list.scrollLeft = scrollLeft - (x - startX) * 1.5; }); list.addEventListener('mouseup', () => { isDragging = false; list.style.cursor = 'grab'; isPaused = false; scheduleNext(); }); list.addEventListener('mouseleave', () => { if (isDragging) { isDragging = false; list.style.cursor = 'grab'; isPaused = false; scheduleNext(); } }); function activate(index) { activeIndex = index; $items.removeClass('on'); $items.eq(activeIndex).addClass('on'); } function scheduleNext() { clearTimeout(timer); timer = setTimeout(() => { if (!isPaused) { activate((activeIndex + 1) % $items.length); } scheduleNext(); // 항상 다음 타이머 예약 }, delay); } activate(0); scheduleNext(); $items.on('click', function () { if (!isDragging) { const idx = $items.index(this); if (idx !== activeIndex) { activate(idx); scheduleNext(); } } }); $('.accordion_list').on('mouseenter', () => { isPaused = true; clearTimeout(timer); }).on('mouseleave', () => { if (!isDragging) { isPaused = false; scheduleNext(); } }); } } // 모바일 Swiper if (window.innerWidth < 768) { const slidesView = window.innerWidth < 480 ? 1.1 : 1.5; new Swiper('.s3Swiper', { loop: true, centeredSlides: true, slidesPerView: slidesView, spaceBetween: 20, speed: 1000, loopAdditionalSlides: 4, autoplay: { delay: 3000, disableOnInteraction: false, }, pagination: { el: '.s3Swiper-pagination', clickable: true, }, }); } // =============================== // =============================== // =============================== // ********** 아코디언 메뉴 ********** $('.accordionContent').hide(); // 2. 헤더 클릭 이벤트 $('.accordionHeader').on('click', function (e) { e.preventDefault(); e.stopPropagation(); const $content = $(this).next('.accordionContent'); $('.accordionContent').not($content).slideUp(200); $('.accordionHeader').not(this).removeClass('active'); $(this).toggleClass('active'); $content.stop().slideToggle(300); }); $(document).on('click', function () { $('.accordionContent').slideUp(200); $('.accordionHeader').removeClass('active'); }); $('.accordionContent').on('click', function (e) { e.stopPropagation(); }); // ============================== // 자필후기 var swiper2 = new Swiper(".s6Swiper", { loop: true, slidesPerView: 3, spaceBetween: 30, speed: 1000, navigation: { nextEl: ".s6Swiper_arrow .swiper-button-next", prevEl: ".s6Swiper_arrow .swiper-button-prev", }, autoplay: { delay: 3000, disableOnInteraction: false, }, breakpoints: { 768: { slidesPerView: 1, spaceBetween: 30, }, 1200: { slidesPerView: 2, spaceBetween: 30, }, }, pagination: { el: '.section6 .s6Swiper_pagination', clickable: true, }, }); // ============================== // 둘러보기 var swiper3 = new Swiper(".s7Swiper", { loop: true, slidesPerView: 1, spaceBetween: 30, speed: 1000, navigation: { nextEl: ".s7Swiper_arrow .swiper-button-next", prevEl: ".s7Swiper_arrow .swiper-button-prev", }, // autoplay: { // delay: 3000, // disableOnInteraction: false, // }, pagination: { el: '.s7Swiper_pagination', clickable: true, }, zoom: true }); // ********** sub103 둘러보기 ********** // 하단 슬라이드 var swiper4 = new Swiper(".sub103 .sub103_Swiper1", { spaceBetween: 20, slidesPerView: 7, centeredSlides: true, freeMode: true, watchSlidesProgress: true, slideToClickedSlide: true, on: { click: function (swiper, event) { swiper.slideTo(swiper.clickedIndex); } }, breakpoints: { 480: { slidesPerView: 5, spaceBetween: 15, }, }, }); var swiper5 = new Swiper(".sub103 .sub103_Swiper2", { spaceBetween: 10, navigation: { nextEl: ".sub103_Swiper_arrow .swiper-button-next", prevEl: ".sub103_Swiper_arrow .swiper-button-prev", }, thumbs: { swiper: swiper4, }, on: { slideChange: function () { swiper4.slideTo(this.activeIndex); } } }); // ============================== // ============================== // ============================== // ============================== const pathName = window.location.pathname; // 예: /base/sub1/01.php 또는 /sub1_01.html // 주소 감지해서 해당 메뉴링크에 효과 줌 $('header nav > ul > li').each(function () { $(this).find('.subMenu a').each(function () { const href = $(this).attr('href'); if (!href) return; const pathMatch = pathName.match(/sub(\d+)/); const hrefMatch = href.match(/sub(\d+)/); if ( pathName === href || pathName.endsWith(href) || (pathMatch && hrefMatch && pathMatch[1] === hrefMatch[1]) ) { $(this).closest('li').parent().closest('li').find('.mainMenu').addClass('on'); } }); }); // 1. 대메뉴(content1) 활성화 로직 $('.content1 a').each(function () { const href = $(this).attr('href'); if (!href) return; // 현재 주소와 링크에서 각각 sub 뒤의 숫자 추출 (예: sub1 -> 1) const pathMatch = pathName.match(/sub(\d+)/); const hrefMatch = href.match(/sub(\d+)/); // 주소가 완전히 같거나, 주소의 끝이 href와 일치할 때 if (pathMatch && hrefMatch && pathMatch[1] === hrefMatch[1]) { $(this).addClass('on'); // 헤더 글자를 현재 메뉴명으로 교체 $(this).closest('.accordionItem').find('.accordionHeader p').text($(this).text()); } }); // 2. 소메뉴(content2) 활성화 로직 (파일명 매칭) $('.content2 a').each(function () { const href = $(this).attr('href'); if (!href) return; // 주소가 완전히 같거나, 주소의 끝이 href와 일치할 때 if (pathName === href || pathName.endsWith(href)) { $(this).addClass('on'); // 헤더 글자를 현재 메뉴명으로 교체 $(this).closest('.accordionItem').find('.accordionHeader p').text($(this).text()); } }); });