merge master into develop - CscListRForm.jsp FAQ 아코디언 버그 수정
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
$(document).ready(function() {
|
||||
showItems();
|
||||
loadBannersSequentially().then(() => {
|
||||
initializeSlider();
|
||||
});
|
||||
});
|
||||
|
||||
const $benefitItems = $('.benefit-item');
|
||||
|
||||
function showItems() {
|
||||
$benefitItems.each(function(index, item) {
|
||||
setTimeout(function() {
|
||||
$(item).css({
|
||||
'transition': 'opacity 0.5s, transform 0.5s',
|
||||
'opacity': '1',
|
||||
'transform': 'translateY(0)'
|
||||
});
|
||||
}, index * 100);
|
||||
});
|
||||
}
|
||||
|
||||
function loadImage(banner) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = function() {
|
||||
resolve(img);
|
||||
};
|
||||
img.onerror = function() {
|
||||
console.error('Failed to load image:', banner.imagePath);
|
||||
reject(new Error(`Failed to load image: ${banner.imagePath}`));
|
||||
};
|
||||
img.src = banner.imagePath;
|
||||
});
|
||||
}
|
||||
|
||||
async function loadBannersSequentially() {
|
||||
const $bannerContainer = $('.benefit_main_banner');
|
||||
for (const banner of bannerData) {
|
||||
try {
|
||||
const img = await loadImage(banner);
|
||||
const $slide = $('<div>').addClass('benefit_bn');
|
||||
const $link = $('<a>').attr('href', banner.linkUrl);
|
||||
$(img).attr('alt', banner.bannerSj);
|
||||
$link.append(img);
|
||||
$slide.append($link);
|
||||
$bannerContainer.append($slide);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initializeSlider() {
|
||||
const $bannerWrap = $('.benefit_main_bannerWrap');
|
||||
if ($bannerWrap.length) {
|
||||
const $slides = $('.benefit_bn');
|
||||
const slideCount = $slides.length;
|
||||
let currentIndex = 0;
|
||||
let interval;
|
||||
|
||||
if (slideCount === 0) {
|
||||
console.warn('슬라이드가 없습니다');
|
||||
return;
|
||||
}
|
||||
|
||||
function showSlide(index) {
|
||||
$slides.hide();
|
||||
$slides.eq(index).show();
|
||||
updatePagination(index);
|
||||
}
|
||||
|
||||
function createPagination() {
|
||||
const $pagination = $('.pagination');
|
||||
$pagination.empty();
|
||||
for (let i = 0; i < slideCount; i++) {
|
||||
const $button = $('<button>').attr('data-index', i);
|
||||
$pagination.append($button);
|
||||
}
|
||||
}
|
||||
|
||||
function updatePagination(index) {
|
||||
$('.pagination button').removeClass('active')
|
||||
.eq(index).addClass('active');
|
||||
}
|
||||
|
||||
function nextSlide() {
|
||||
currentIndex = (currentIndex + 1) % slideCount;
|
||||
showSlide(currentIndex);
|
||||
}
|
||||
|
||||
function startSliding() {
|
||||
interval = setInterval(nextSlide, 3000);
|
||||
}
|
||||
|
||||
function stopSliding() {
|
||||
clearInterval(interval);
|
||||
}
|
||||
|
||||
createPagination();
|
||||
showSlide(currentIndex);
|
||||
startSliding();
|
||||
|
||||
$('.pagination').on('click', 'button', function() {
|
||||
currentIndex = parseInt($(this).attr('data-index'));
|
||||
showSlide(currentIndex);
|
||||
});
|
||||
|
||||
$('.benefit_main_banner').on('click', nextSlide);
|
||||
|
||||
$bannerWrap.on('mouseenter', stopSliding)
|
||||
.on('mouseleave', startSliding);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user