Refactor lightbox functionality to initialize only if elements exist, improving performance and preventing errors. Maintain existing event listeners for closing the lightbox and handling keyboard interactions.
This commit is contained in:
@@ -77,6 +77,8 @@
|
||||
const lightboxClose = document.querySelector('.lightbox-close');
|
||||
const projectImages = document.querySelectorAll('.popup-image');
|
||||
|
||||
// Only initialize lightbox if elements exist
|
||||
if (lightbox && lightboxImage && lightboxClose && projectImages.length > 0) {
|
||||
projectImages.forEach(image => {
|
||||
image.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
@@ -109,6 +111,7 @@
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Sticky Navigation
|
||||
$(window).on('scroll', function() {
|
||||
|
||||
Reference in New Issue
Block a user