-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
192 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
const modal = document.getElementById('modal'); | ||
const modalImg = document.getElementById('modal-image'); | ||
const modalControls = document.querySelectorAll('.modal-control'); | ||
const modalPrev = document.getElementById('modal-prev'); | ||
const modalNext = document.getElementById('modal-next'); | ||
const modalClose = document.getElementById('modal-close'); | ||
const modalDetails = document.getElementById('modal-details-box'); | ||
const galleryImages = document.querySelectorAll('.photo-thumbnail'); | ||
let currentSlideIndex = 0; | ||
|
||
function preloadImages() { | ||
photoSrcs.forEach((src) => { | ||
const img = new Image(); | ||
img.src = src; | ||
}); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
preloadImages(); // Preload images when the DOM is ready | ||
}); | ||
|
||
galleryImages.forEach((image) => { | ||
image.addEventListener('click', () => { | ||
showModal(); | ||
showPhoto(parseInt(image.dataset.orderindex)); | ||
}); | ||
}); | ||
|
||
modal.addEventListener('click', (e) => { | ||
if (e.target === modal || e.target.classList.contains('close')) { | ||
hideModal(); | ||
} | ||
}); | ||
|
||
modalImg.addEventListener('load', function() { | ||
modalControls.forEach( (c) => { | ||
c.classList.add('hidden'); | ||
}); | ||
}); | ||
|
||
modalPrev.addEventListener('click', () => { | ||
showPhoto(currentSlideIndex - 1); | ||
}); | ||
|
||
modalNext.addEventListener('click', () => { | ||
showPhoto(currentSlideIndex + 1); | ||
}); | ||
|
||
function showModal() { | ||
modal.classList.add('visible'); | ||
document.body.style.overflow = 'hidden'; // Hide the scrollbar | ||
} | ||
|
||
function hideModal() { | ||
modal.classList.remove('visible'); | ||
document.body.style.overflow = 'auto'; // Restore the scrollbar | ||
modalPrev.classList.remove('hidden'); | ||
modalNext.classList.remove('hidden'); | ||
modalImg.src = ""; | ||
} | ||
|
||
function showPhoto(n) { | ||
if (n >= photoSrcs.length) { | ||
n = 0; | ||
} | ||
if (n < 0) { | ||
n = photoSrcs.length - 1; | ||
} | ||
currentSlideIndex = n; | ||
modalImg.src = photoSrcs[n]; | ||
const details = photoDetails[n]; | ||
if (details) { | ||
modalDetails.innerHTML = "<p>" + details + "</p>" | ||
modalDetails.classList.add('visible'); | ||
} else if (modalDetails.classList.contains('visible')) { | ||
modalDetails.classList.remove('visible'); | ||
} | ||
} | ||
|
||
document.addEventListener('keydown', (e) => { | ||
if (modal.classList.contains('visible')) { | ||
if (e.key === 'ArrowLeft' || e.keyCode === 37) { | ||
showPhoto(currentSlideIndex - 1); | ||
} else if (e.key === 'ArrowRight' || e.keyCode === 39) { | ||
showPhoto(currentSlideIndex + 1); | ||
} else if (e.key === 'Escape' || e.keyCode === 27) { | ||
hideModal(); | ||
} | ||
} | ||
}); | ||
|
||
let touchStartX = 0; | ||
let touchEndX = 0; | ||
|
||
document.addEventListener('touchstart', e => { | ||
if (modal.classList.contains('visible')) { | ||
touchStartX = e.changedTouches[0].screenX | ||
} | ||
}) | ||
|
||
document.addEventListener('touchend', e => { | ||
if (modal.classList.contains('visible')) { | ||
if (e.target === modalClose) { | ||
hideModal(); | ||
} | ||
touchEndX = e.changedTouches[0].screenX | ||
updateOnSwipe() | ||
} | ||
}) | ||
function updateOnSwipe() { | ||
const diff = touchEndX - touchStartX | ||
if (diff < -50) { | ||
showPhoto(currentSlideIndex - 1); | ||
} else if (diff > 50) { | ||
showPhoto(currentSlideIndex + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
layout: default | ||
title: Simon Rey Photo | ||
additional_script: gallery.js | ||
--- | ||
|
||
# Me, Myself, and My Photos | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
--- | ||
layout: default | ||
title: Insides | Simon Rey | ||
navID: nav-insides | ||
additional_script: gallery.js | ||
--- | ||
|
||
# Insides | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.