/* * Name : common.min.js * Version : 1.1.1 * Product : prime05 * Author : 1px studio * Date : 2024.08.23 * Desc : 포인트컬러(style preview) 적용 + 모바일 메뉴 분기점 숨김 --------------------------------------------------- */ $(function(){ /* PRIME COMMON : s */ !function e() { let t = document.getElementById("isIndex"); if (t && "Y" == t.value) { document.getElementById('sjs')?.remove(); document.getElementById('scss')?.remove(); } else { document.getElementById('mjs')?.remove(); document.getElementById('mcss')?.remove(); } }(); function loaded_script() { // hide spinner let t = $("#page-loader"); t.find(".loader-stage").fadeOut("slow", function() { setTimeout(function() { t.fadeOut("slow"); }, 100); }); // sub page hero init if (document.getElementById("isIndex")==null) { let hero = $('.hero'); hero.addClass('--load'); } } window.onload = loaded_script(); /* PRIME COMMON : e */ // 헤더 초기화 function navbar_init() { const header = $('#header'); const menuItems = $('#header .gnb > ul > li'); const megamenuBg = $('#header .megamenu-bg'); const hamburger = $('#header .button-hamburger'); const backdrop = $('#mobile-header .backdrop'); let bgHeight = 0; menuItems.each(function () { let $this = $(this); if ( $this.find('>.submenu-items').outerHeight() >= bgHeight ) { bgHeight = $this.find('>.submenu-items').outerHeight(); } }); megamenuBg.height(0); menuItems.on('mouseenter', function() { header.addClass('active'); gsap.to('#header .megamenu-bg', { autoAlpha: 1, height: bgHeight, duration: 0.3 }); $('#header .submenu-items').stop().fadeIn(400); }); $('#header .gnb').on('mouseleave', function() { header.removeClass('active'); $('#header .submenu-items').stop().fadeOut(100); gsap.to('#header .megamenu-bg', { autoAlpha: 0, height: 0, duration: 0.3 }); }); hamburger.on('click', (e) => { let $this = $(e.currentTarget); $this.attr('aria-expanded', function(i, attr) { return attr == 'true' ? 'false' : 'true' }); $this.toggleClass('active'); header.toggleClass('nav-open'); backdrop.stop().fadeToggle(400); }); $('#mobile-header .inner-content > ul > li > a').on('click', (e) => { let $this = $(e.currentTarget); if ( $this.siblings('.submenu-items').length ) { e.preventDefault(); if ( !$this.parent().hasClass('open') ) { $('#mobile-header .inner-content > ul > li').removeClass('open'); $('#mobile-header .inner-content > ul > li .submenu-items').stop().slideUp(300); $this.parent().addClass('open'); $this.siblings('.submenu-items').stop().slideDown(300); } else { $this.parent().removeClass('open'); $this.siblings('.submenu-items').stop().slideUp(300); } } }); } navbar_init(); // 스티키 네비게이션 function sticky_navbar() { let st = $(window).scrollTop(); if ( st >= 100 ) { header.addClass('sticky'); } else { header.removeClass('sticky'); } } /* 부드러운 스크롤 적용 */ const lenis = new Lenis({ duration: 0.8, // 애니메이션 지속시간 easing: (x) => 1 - Math.pow(1 - x, 3), // 애니메이션 easing 효과 wheelMultiplier: 2 // 마우스휠 강도 }); lenis.on('scroll', (e) => { //console.log(e); }); function raf(time) { lenis.raf(time); requestAnimationFrame(raf); } requestAnimationFrame(raf); /* 스크롤 시 이벤트 */ let before_scroll_top = 0; let header_timer = null; let header = $("#header"); function clearHeaderTimeout() { clearTimeout(header_timer); } function setHeaderTimeout() { clearHeaderTimeout(); let menu_opened = $("#hamburger").hasClass("open") && window.outerWidth < 1280; if (menu_opened) return; header_timer = setTimeout(function(){ header.addClass("hide"); }, 2500); } $(window).on('scroll', function() { sticky_navbar(); let st = $(window).scrollTop(); if (before_scroll_top > st) { header.removeClass("hide"); } if ( st >= 200 ) { header.addClass('fixed'); setHeaderTimeout(); $("#quick-btns").addClass('show'); } else { header.removeClass('fixed'); clearHeaderTimeout(); $("#quick-btns").removeClass('show'); } before_scroll_top = st; }); header.on("mouseover", function(e){ clearHeaderTimeout(); }); header.on("mouseout", function(e){ setHeaderTimeout(); }); /* gnb 메뉴 호버 */ function setGnbWidth() { let $gnbs = $("#header .gnb > ul > li"); let zero = false; $.each($gnbs, function(i) { if ($(this).outerWidth() == 0) { $("#header").attr("data-gnb", 0); zero = true; return; } else { $(this).css("width", $(this).outerWidth()+"px"); $("#header").attr("data-gnb", 1); } }); if (!zero) { let $subs = $("#header .gnb > ul > li .gnb-sub"); $.each($subs, function(i) { $(this).css("width", $(this).outerWidth()+"px"); }); } } setGnbWidth(); $(window).on('resize', () => { if ($("#header").attr("data-gnb")==false && window.outerWidth > 1280) { setGnbWidth(); } if (window.outerWidth > 1279) { $("#header-mb").hide(); $("#hamburger").removeClass("open"); } }); /* mobile 메뉴 */ let $header_mobile = $("#header-mb"); let menu_clicked = false; $("#hamburger").on("click", function(e){ if ( !$(this).hasClass('open') ) { if (menu_clicked) return false; menu_clicked = true; clearHeaderTimeout(); $(this).addClass('open'); gsap.set($header_mobile, { display: "block" }).then(function (){ gsap.to($header_mobile, {opacity: 1, duration: 0.8, ease: "power2.out"}).then(function() { menu_clicked = false; }); }); } else { if (menu_clicked) return false; menu_clicked = true; $(this).removeClass('open'); gsap.to($header_mobile, {opacity: 0, duration: 0.8, ease: "power2.out"}).then(function (){ gsap.set($header_mobile, { display: "none" }).then(function() { menu_clicked = false; setHeaderTimeout(); }); }); } }); $("#header-mb .gnb-top").on("click", function(e){ let gnbsub = $(this).next(".gnb-sub"); if (gnbsub.hasClass("open")) { gnbsub.removeClass("open"); return; } $("#header-mb .gnb-sub").removeClass("open"); gnbsub.addClass("open"); }); /* 커스텀 커서 */ function customCursor() { let isMobile = /Mobi/i.test(window.navigator.userAgent); if (isMobile) { $(".px-cursor").remove(); return; } const $ball = document.querySelector('.cursor-ball'); const $ball_inner = document.querySelector('.cursor-inner'); $(document).on('mousemove', onMouseMove); $(document).on("mouseenter", "a, button", onMouseHover); $(document).on("mouseleave", "a, button", onMouseHoverOut); $('.hero-buttons *').on("mouseenter", onMouseHover2); $('.hero-buttons *').on("mouseleave", onMouseHoverOut2); function onMouseMove(e) { TweenMax.to($ball, .6, { x: e.clientX - 34, y: e.clientY - 34 }); } function onMouseHover() { TweenMax.to($ball, .3, { scale: 0.5 }); } function onMouseHoverOut() { TweenMax.to($ball, .3, { scale: 1 }); } function onMouseHover2(e) { $($ball_inner).addClass("big"); let cursor_txt = $(e.target).attr('data-cursor'); $($ball).css({"mix-blend-mode": "unset"}); $($ball).append('
'+cursor_txt+'
'); } function onMouseHoverOut2() { $($ball_inner).removeClass("big"); $($ball).css({"mix-blend-mode": "difference"}); $($ball).find(".text").remove(); } } // customCursor(); /* footer email copy */ $("#footer .footer-email").on("click", function(e){ let copy = $(this).children().eq(0).text(); window.navigator.clipboard.writeText(copy).then(() => {}) .catch((error) => { if (error) { alert(`[알림]\n실제 사이트에서는 버튼에 기재된 메일 주소(${copy})가 \n자동으로 복사되나, 브라우저 정책으로 상품 미리보기(iframe)에서는 실행되지 않으니 참고 바랍니다.`); } }) .finally(() => { $("#footer .footer-email div").css("transform", "translateY(-200%)"); setTimeout(function(){ $("#footer .footer-email div").removeAttr("style"); }, 2000); }); }); $("#quick-btns .quick-more").on("click", function(e){ $("#quick-btns .quick-list").toggleClass("active"); }); AOS.init({ duration: 800, startEvent: 'load' // once: true }); });