-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
89 lines (75 loc) · 3.3 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
document.addEventListener('DOMContentLoaded', function() {
// Screenshot carousel functionality
const carousel = document.querySelector('.screenshot-carousel');
const screenshots = document.querySelector('.screenshots');
const prevButton = carousel.querySelector('.prev');
const nextButton = carousel.querySelector('.next');
let currentIndex = 0;
// Function to load images from the /imgs/views/ directory
async function loadScreenshots() {
try {
const response = await fetch('imgs/views/manifest.json');
const images = await response.json();
images.forEach(imageName => {
const slide = document.createElement('div');
slide.className = 'screenshot-slide';
const img = document.createElement('img');
img.src = `imgs/views/${imageName}`;
img.alt = 'App Screenshot';
img.loading = 'lazy'; // Enable lazy loading
slide.appendChild(img);
screenshots.appendChild(slide);
});
} catch (error) {
console.error('Error loading screenshots:', error);
}
}
function updateCarousel() {
const slideWidth = document.querySelector('.screenshot-slide')?.offsetWidth || 0;
const gap = 16; // 1rem gap
const offset = currentIndex * -(slideWidth + gap);
screenshots.style.transform = `translateX(${offset}px)`;
}
function updateButtonsVisibility() {
const totalSlides = screenshots.children.length;
const slidesPerView = window.innerWidth <= 768 ? 1 : window.innerWidth <= 1024 ? 2 : 3;
const maxIndex = Math.max(0, totalSlides - slidesPerView);
prevButton.style.visibility = currentIndex <= 0 ? 'hidden' : 'visible';
nextButton.style.visibility = currentIndex >= maxIndex ? 'hidden' : 'visible';
}
prevButton.addEventListener('click', () => {
currentIndex = Math.max(currentIndex - 1, 0);
updateCarousel();
updateButtonsVisibility();
});
nextButton.addEventListener('click', () => {
const totalSlides = screenshots.children.length;
const slidesPerView = window.innerWidth <= 768 ? 1 : window.innerWidth <= 1024 ? 2 : 3;
const maxIndex = Math.max(0, totalSlides - slidesPerView);
currentIndex = Math.min(currentIndex + 1, maxIndex);
updateCarousel();
updateButtonsVisibility();
});
// Handle window resize
window.addEventListener('resize', () => {
updateCarousel();
updateButtonsVisibility();
});
// Load screenshots when the page loads
loadScreenshots();
// Form submission handling
var submitted = false;
const gform = document.getElementById('gform');
if (gform) {
gform.addEventListener('submit', function(e) {
const formElements = gform.querySelectorAll('input, textarea, button');
formElements.forEach(element => {
element.style.transition = 'opacity 2s';
element.style.opacity = '0';
});
setTimeout(() => {
gform.innerHTML = '<p class="success-message">Thank you for your feedback!</p>';
}, 2000);
});
}
});