forked from chhavibhalla/igdtuw-overview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (31 loc) · 1.41 KB
/
app.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
const imageContainer = document.querySelector('.image-container');
const prevBtn = document.querySelector('.prev-btn');
const nextBtn = document.querySelector('.next-btn');
// Get all the slides (image spans)
const slides = document.querySelectorAll('.image-container span');
let currentSlide = 0; // Start from the first slide
const totalSlides = slides.length; // Total number of slides
// Update the rotation of the carousel
function updateCarousel() {
// Calculate the angle for the current slide (360 / totalSlides) times the slide number
const angle = (360 / totalSlides) * currentSlide;
imageContainer.style.transform = `perspective(1000px) rotateY(-${angle}deg)`;
}
// Add event listeners for the buttons
prevBtn.addEventListener('click', () => {
// Move to the previous slide
currentSlide = (currentSlide - 1 + totalSlides) % totalSlides; // Loop around if out of bounds
updateCarousel();
});
nextBtn.addEventListener('click', () => {
// Move to the next slide
currentSlide = (currentSlide + 1) % totalSlides; // Loop around if out of bounds
updateCarousel();
});
// Optional: Pause the automatic rotation when interacting
imageContainer.addEventListener('mouseover', () => {
imageContainer.style.animationPlayState = 'paused'; // Stop rotation on hover
});
imageContainer.addEventListener('mouseout', () => {
imageContainer.style.animationPlayState = 'running'; // Resume rotation when not hovered
});