File size: 2,378 Bytes
f696103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Carousel functionality with infinite loop
let currentSlide = 0;
const carousel = document.getElementById('buildCarousel');
const items = carousel.querySelectorAll('.carousel-item');
const totalSlides = items.length;

function updateCarousel() {
    // Remove active class from all items
    items.forEach(item => item.classList.remove('active'));
    
    // Add active class to current item
    items[currentSlide].classList.add('active');
    
    // Calculate offset for centered carousel with visible adjacent items
    const itemWidth = 70; // percentage
    const offset = -currentSlide * itemWidth + 15; // 15% to center
    carousel.style.transform = `translateX(${offset}%)`;
}

function moveCarousel(direction) {
    // Calculate new slide index
    currentSlide += direction;
    
    // Loop around (infinite loop)
    if (currentSlide < 0) {
        currentSlide = totalSlides - 1;
    } else if (currentSlide >= totalSlides) {
        currentSlide = 0;
    }
    
    updateCarousel();
}

// Initialize carousel
updateCarousel();

// Auto-play carousel
let autoplayInterval = setInterval(() => {
    moveCarousel(1);
}, 5000);

// Pause autoplay on hover
carousel.parentElement.addEventListener('mouseenter', () => {
    clearInterval(autoplayInterval);
});

carousel.parentElement.addEventListener('mouseleave', () => {
    autoplayInterval = setInterval(() => {
        moveCarousel(1);
    }, 5000);
});

// Optional: Auto-play carousel
// Uncomment the following lines if you want automatic sliding
/*
let autoplayInterval;

function startAutoplay() {
    autoplayInterval = setInterval(() => {
        moveCarousel(1);
    }, 5000); // Change slide every 5 seconds
}

function stopAutoplay() {
    clearInterval(autoplayInterval);
}

// Start autoplay on load
startAutoplay();

// Stop autoplay when user interacts with carousel
carousel.addEventListener('mouseenter', stopAutoplay);
carousel.addEventListener('mouseleave', startAutoplay);
*/

// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        const target = document.querySelector(this.getAttribute('href'));
        if (target) {
            target.scrollIntoView({
                behavior: 'smooth',
                block: 'start'
            });
        }
    });
});