function hambergerMenu() { var vw = $(window).width(); var hoverMode = false; var tl = gsap.timeline(); //tablet 모드에서 메뉴아이콘 hover 제어 if(($('html').is('.mobile')) || (vw <= 1279)){ $('.h-bar').off('hover'); console.log('off-hover-menu'); } else { hoverMenuFn(); } //메뉴아이콘 클릭 $('.h-bar').on('click', function(e) { $(this).toggleClass('is-open'); $('header').toggleClass('open'); if($(this).hasClass('is-open')) { openMenu(this); $('.h-bar').off('hover'); $('#all_nav_g').stop(true).fadeIn(); } else { closeMenu(this); $('#all_nav_g').stop(true).delay(300).fadeOut(); if(vw >= 1279) { hoverMenuFn(); } } }); //오픈메뉴 배경 클릭시 아웃 $('#all_nav_g').on('click', function(e) { e.stopPropagation(); $('.h-bar').removeClass('is-open'); $('header').removeClass('open'); closeMenu('.h-bar'); $('#all_nav_g').stop(true).delay(300).fadeOut(); if(vw >= 1279) { hoverMenuFn(); } }); function initMenu(selector) { var timeout; window.addEventListener("resize", resize); resize(); function resize() { var vw = $(window).width(); //resize시 메뉴가 열려있지 않으면서 hover 이벤트가 아닐때 return (중복 애니메이션 제어) if((!$('.h-bar').hasClass('is-open')) && (!hoverMode)) { gsap.set($(selector).find('.menu-icon__bar'), {clearProps:"all"}); $('.menu-icon__bar').removeAttr('style'); return; } if(timeout) clearTimeout(timeout); if(true) { tl.kill(); tl = gsap.timeline({ defaults: { ease: 'slow(0.5, 0.7, false)', duration: .3, } }); tl .to($(selector).find('.top'), { rotate : '90deg', scaleX: vw >= 768 ? '0.6' : '0.5', x: vw >= 768 ? '-10' : '-9', y: vw >= 768 ? '0' : '0', },'init') .to($(selector).find('.left'), { scaleX: vw >= 768 ? '0.6' : '0.5', x: vw >= 768 ? '-20' : '-15', y: vw >= 768 ? '0' : '1', }, 'init+=0.03') .to($(selector).find('.bottom'), { rotate : '-90deg', scaleX: vw >= 768 ? '0.6' : '0.5', x: vw >= 768 ? '-10' : '-9', y: vw >= 768 ? '-1' : '0', }, 'init+=0.1') .to($(selector).find('.right'), { rotate : '-180deg', scaleX: vw >= 768 ? '0.6' : '0.5', duration: .6, x: vw >= 768 ? '0' : '-3', y: vw >= 768 ? '-20' : '-12', }, 'init') return tl; } } } function openMenu(selector) { console.log('open'); initMenu(selector); setTimeout(function () { openMenuMotion(); }, 300); var tl = gsap.timeline(); tl.to($(selector), { rotate: '45deg'}, 'open') return tl; } function closeMenu(selector) { tl.kill(); tl = gsap.timeline(); closeMenuMotion(); tl .to($(selector), { rotate: '0deg'}, 'close') .to($(selector).find('.top'), { x : 0, y:0, rotate: '0deg', scaleX: '1'}, 'close') .to($(selector).find('.left'), { x : 0 , y:0, scaleX: '1'}, 'close') .to($(selector).find('.bottom'), { x : 0, y:0, rotate: '0deg', scaleX: '1'}, 'close') .to($(selector).find('.right'), { x : 0, y: 0, rotate : '0deg', scaleX: '1'}, 'close') .set($(selector).find('.menu-icon__bar'), {clearProps:"all"}) $('.menu-icon__bar').removeAttr('style'); return tl; } function openMenuMotion() { gsap.to('.all_nav li .b', .4, {height:'100%', ease: 'none', opacity:1}); gsap.to('.sns_b', .4, {height:'100%', ease: 'none'}); gsap.fromTo('.all_nav .cate_num', .2, {y: -15}, {y:0, delay:0.3}); } function closeMenuMotion() { gsap.to('.all_nav li .b', .2, {height:'0%', ease: 'none', opacity:0, delay:0.05}); gsap.to('.sns_b', .2, {height:'0%', ease: 'none', delay:0.05}); gsap.to('.all_nav .cate_num', .1, {clearProps:"all"}); } function hoverMenuFn() { $('.h-bar:not(.is-open)').hover(function() { hoverMode = true; setTimeout(function () { initMenu('.h-bar'); }, 100); }, function(){ hoverMode = false; if(!$(this).hasClass('is-open')) { closeMenu(this); } $('.menu-icon__bar').removeAttr('style'); }); } }