File size: 2,849 Bytes
8393747
39eff7e
 
8393747
 
 
 
 
 
 
 
39eff7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8393747
39eff7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8393747
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39eff7e
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
document.addEventListener('DOMContentLoaded', function () {
    const navbar = document.querySelector('.header');
    
    // Menambahkan kelas "scrolled" saat scroll
    window.addEventListener('scroll', function() {
        if (window.scrollY > 0) {
            navbar.classList.add('scrolled');
        } else {
            navbar.classList.remove('scrolled');
        }
    });
    
    const sections = document.querySelectorAll('.section');
    let currentIndex = 0;
    const totalSections = sections.length;

    // Fungsi untuk scroll ke section tertentu
    function scrollToSection(index) {
        if (index < 0 || index >= totalSections) return;  // Membatasi scroll agar tidak keluar dari index
        const section = sections[index];
        window.scrollTo({
            top: section.offsetTop,
            behavior: 'smooth',  // Scroll dengan smooth
        });
    }

    // Event listener untuk scroll
    let isScrolling = false;  // Menghindari scroll terlalu cepat
    window.addEventListener('wheel', function (e) {
        if (isScrolling) return;  // Menghindari scroll berulang

        isScrolling = true;

        if (e.deltaY > 0 && currentIndex < totalSections - 1) {
            currentIndex++;  // Scroll ke bawah
        } else if (e.deltaY < 0 && currentIndex > 0) {
            currentIndex--;  // Scroll ke atas
        }

        // Scroll ke section yang sesuai
        scrollToSection(currentIndex);

        // Matikan status scrolling setelah animasi selesai
        setTimeout(() => {
            isScrolling = false;
        }, 1000);  // Durasi animasi sekitar 1 detik
    });

    // Fungsi untuk animasi muncul setiap section
    function animateSections() {
        sections.forEach((section) => {
            // Memeriksa apakah section sudah di view port
            const sectionPosition = section.getBoundingClientRect();
            if (sectionPosition.top < window.innerHeight && sectionPosition.bottom >= 0) {
                section.classList.add('visible');
            }
        });
    }

    // Trigger animasi ketika halaman dimuat
    animateSections();

    // Animasi muncul saat scroll
    window.addEventListener('scroll', animateSections);
    
    // Event listener untuk klik pada navbar
    document.querySelectorAll('.navigation ul li a').forEach(anchor => {
        anchor.addEventListener('click', function(e) {
            e.preventDefault();

            // Ambil id dari link
            const targetId = this.getAttribute('href').substring(1);

            // Temukan section yang sesuai
            const targetSection = document.getElementById(targetId);

            // Scroll ke section tersebut dengan transisi halus
            targetSection.scrollIntoView({
                behavior: 'smooth',
                block: 'start'
            });
        });
    });
});