Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ const PhotoCarousel = {
currentIndex: 2, // Start with center card (index 2)
positions: ['far-left', 'left', 'center', 'right', 'far-right'],
isAnimating: false,
isVisible: false, // ⚑ bolt: cache visibility

init() {
this.carousel = document.getElementById('photo-carousel');
Expand All @@ -890,6 +891,14 @@ const PhotoCarousel = {

if (!this.cards.length) return;

// ⚑ bolt: observe visibility to avoid synchronous getBoundingClientRect
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
this.isVisible = entry.isIntersecting;
});
}, { threshold: 0 }); // trigger as soon as any part enters/leaves
observer.observe(this.carousel);

// Set initial caption
this.updateCaption(this.currentIndex);

Expand Down Expand Up @@ -1044,9 +1053,7 @@ const PhotoCarousel = {
},

isInView() {
if (!this.carousel) return false;
const rect = this.carousel.getBoundingClientRect();
return rect.top < window.innerHeight && rect.bottom > 0;
return this.isVisible;
},

navigate(direction) {
Expand Down