Update project descriptions, enhance image handling, and add lightbox functionality
This commit is contained in:
39
js/custom.js
39
js/custom.js
@@ -70,4 +70,43 @@
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add lightbox functionality
|
||||
const lightbox = document.querySelector('.lightbox');
|
||||
const lightboxImage = document.querySelector('.lightbox-image');
|
||||
const lightboxClose = document.querySelector('.lightbox-close');
|
||||
const projectImages = document.querySelectorAll('.popup-image');
|
||||
|
||||
projectImages.forEach(image => {
|
||||
image.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
const imgSrc = image.getAttribute('href');
|
||||
const imgAlt = image.querySelector('img').getAttribute('alt');
|
||||
|
||||
lightboxImage.setAttribute('src', imgSrc);
|
||||
lightboxImage.setAttribute('alt', imgAlt);
|
||||
lightbox.classList.add('active');
|
||||
document.body.style.overflow = 'hidden';
|
||||
});
|
||||
});
|
||||
|
||||
lightboxClose.addEventListener('click', () => {
|
||||
lightbox.classList.remove('active');
|
||||
document.body.style.overflow = '';
|
||||
});
|
||||
|
||||
lightbox.addEventListener('click', (e) => {
|
||||
if (e.target === lightbox) {
|
||||
lightbox.classList.remove('active');
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Close lightbox with Escape key
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape' && lightbox.classList.contains('active')) {
|
||||
lightbox.classList.remove('active');
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
});
|
||||
})(window.jQuery);
|
||||
|
||||
Reference in New Issue
Block a user