var ALWAYS_OPEN = true; // 배너 항상 열려있는 상태면 true 로 바꿔 주세요. var REMEMBER_CLOSE = true; // 하루동안 보지 않기를 지원할려면 true 로 바꿔 주세요. var REMEMBER_DATE = 1; // 날짜 단위. 하루면 1. var carouseling = false; function leftCarousel() { if (carouseling) return; carouseling = true; var active = $('#BANNER_WRAP .carousel_inner .item.active'); var last = $('#BANNER_WRAP .carousel_inner .item').last(); active.before(last); var width = last.width(); $('#BANNER_WRAP .carousel_inner').css('left', '-' + width + 'px'); $('#BANNER_WRAP .carousel_inner').animate({ 'left': 0 }, 500, function () { active.removeClass('active').prev().addClass('active'); carouseling = false; }); } function rightCarousel() { if (carouseling) return; carouseling = true; var active = $('#BANNER_WRAP .carousel_inner .item.active'); var width = active.width(); $('#BANNER_WRAP .carousel_inner').animate({ 'left': '-=' + width }, 500, function () { active.removeClass('active').next().addClass('active'); $('#BANNER_WRAP .carousel_inner').css('left', '0').append(active); carouseling = false; }); } function autoCarousel() { setTimeout(function () { rightCarousel(); autoCarousel(); }, 3000); } function initCarousel() { $('#BANNER_WRAP .carousel-control.left').click(function (event) { event.preventDefault(); leftCarousel(); return false; }); $('#BANNER_WRAP .carousel-control.right').click(function (event) { event.preventDefault(); rightCarousel(); return false; }); autoCarousel(); } // ✅ 모바일 스와이프 이벤트 추가 function addTouchSwipe() { var startX = 0; var endX = 0; const $carousel = $('#BANNER_WRAP .carousel_inner'); $carousel.on('touchstart', function (e) { startX = e.originalEvent.touches[0].clientX; }); $carousel.on('touchmove', function (e) { endX = e.originalEvent.touches[0].clientX; }); $carousel.on('touchend', function (e) { var deltaX = endX - startX; if (deltaX > 50) { leftCarousel(); // 오른쪽으로 밀었을 때 (이전) } else if (deltaX < -50) { rightCarousel(); // 왼쪽으로 밀었을 때 (다음) } startX = 0; endX = 0; }); } $(document).ready(function () { initCarousel(); addTouchSwipe(); // ✅ 스와이프 제스처 활성화 if (!ALWAYS_OPEN) { if (REMEMBER_CLOSE && '1' == $.cookie('TODAY_BANNER_CLOSE')) { hideBanner(false); } else { setTimeout(function () { showBanner(); }, 1000); } } else { $('#BANNER_WRAP').css('margin', 0); } });