jQuery(function ($) { // 단일 요소에 페이드인 효과 function fadeInStaggered($items, delay = 200) { const scrollTop = $(window).scrollTop(); const windowHeight = $(window).height(); $items.each(function (i) { const $el = $(this); if (!$el.length) return; const elTop = $el.offset().top; if (scrollTop + windowHeight > elTop + 50 && !$el.hasClass('active')) { setTimeout(function () { $el.addClass('active'); }, i * delay); } }); } //서브페이지에도 쓸수있게 하는 함수 function fadeInOnScroll($el) { if (!$el.length) return; // 존재 여부 체크 const elTop = $el.offset().top; const scrollTop = $(window).scrollTop(); const windowHeight = $(window).height(); if (scrollTop + windowHeight > elTop + 50 && !$el.hasClass('active')) { $el.addClass('active'); } } // 여러 요소 위로 페이드업 등장 function fadeUpOnScroll($targets, delay = 0) { $targets.each(function (i) { const $el = $(this); if (!$el.length) return; const elTop = $el.offset().top; const scrollTop = $(window).scrollTop(); const windowHeight = $(window).height(); if (scrollTop + windowHeight > elTop + 50 && !$el.hasClass('active')) { setTimeout(function () { $el.addClass('active'); }, delay * i); } }); } // 개별 딜레이있는 페이드업 function fadeUpSingle($el, delay = 0) { if (!$el.length) return; const elTop = $el.offset().top; const scrollTop = $(window).scrollTop(); const windowHeight = $(window).height(); if (scrollTop + windowHeight > elTop + 50 && !$el.hasClass('active')) { setTimeout(function () { $el.addClass('active'); }, delay); } } $(window).on('scroll load', function () { // 도로록, item 하나씩 올라오기 fadeInStaggered($('.item')); fadeUpOnScroll($('.history-row')); // 좌우에서 나오기 fadeInOnScroll($('.up')); fadeInOnScroll($('.left')); fadeInOnScroll($('.right')); // 하나씩 위로 올라오기 /딜레이X fadeUpOnScroll($('.box')); fadeUpOnScroll($('.greet-wrap .main-title')); fadeUpOnScroll($('.greeting-txt-right-con p'), 200); // 서브페이지, 딜레이 있는 페이드인 fadeUpSingle($('.sub-title-con'), 0); // 바로 : 타이틀 fadeUpSingle($('.sub-con'), 300); // 0.3초 후 등장 :섹션 }); });