Community
커뮤니티
제목
레스토랑 홈페이지 제작-5강 메뉴 페이지 만들기 script 코드
유튜브
작성자
itconnect
작성일
2025-06-21 09:45
조회
270
영상에서 나온 설명과 같이 아래 코드 삽입 시 script와 /script 사이에 붙여주셔야 합니다.
document.addEventListener('DOMContentLoaded', function() {
const tabs = document.querySelectorAll('.e-n-tab-title');
function findImageElement() {
const imageContainer = document.querySelector('.change_image');
if (imageContainer) {
const img = imageContainer.querySelector('img');
if (img) return img;
}
return null;
}
tabs.forEach(tab => {
tab.addEventListener('click', function() {
const tabIndex = this.getAttribute('data-tab-index');
let imageUrl = '';
switch(tabIndex) {
case '1':
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/classic-menu-scaled.webp';
break;
case '2':
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/vegit-menu-scaled.webp';
break;
case '3':
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/seefood-menu-scaled.webp';
break;
default:
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/classic-menu-scaled.webp';
}
const currentImage = findImageElement();
if (!currentImage) return;
currentImage.style.transition = 'opacity 0.3s ease';
currentImage.style.opacity = '0.5';
const cacheBuster = '?v=' + Date.now();
currentImage.setAttribute('src', imageUrl + cacheBuster);
currentImage.removeAttribute('srcset');
currentImage.onload = function() {
currentImage.style.opacity = '1';
};
currentImage.onerror = function() {
currentImage.style.opacity = '1';
};
});
});
});
document.addEventListener('DOMContentLoaded', function() {
const tabs = document.querySelectorAll('.e-n-tab-title');
function findImageElement() {
const imageContainer = document.querySelector('.change_image');
if (imageContainer) {
const img = imageContainer.querySelector('img');
if (img) return img;
}
return null;
}
tabs.forEach(tab => {
tab.addEventListener('click', function() {
const tabIndex = this.getAttribute('data-tab-index');
let imageUrl = '';
switch(tabIndex) {
case '1':
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/classic-menu-scaled.webp';
break;
case '2':
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/vegit-menu-scaled.webp';
break;
case '3':
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/seefood-menu-scaled.webp';
break;
default:
imageUrl = 'https://restaurant.homepage.works/wp-content/uploads/2025/02/classic-menu-scaled.webp';
}
const currentImage = findImageElement();
if (!currentImage) return;
currentImage.style.transition = 'opacity 0.3s ease';
currentImage.style.opacity = '0.5';
const cacheBuster = '?v=' + Date.now();
currentImage.setAttribute('src', imageUrl + cacheBuster);
currentImage.removeAttribute('srcset');
currentImage.onload = function() {
currentImage.style.opacity = '1';
};
currentImage.onerror = function() {
currentImage.style.opacity = '1';
};
});
});
});
전체 0
전체게시글 80