File size: 3,668 Bytes
b6db5aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
95
96
97
98
99
100
document.addEventListener('DOMContentLoaded', function() {
    // Smooth scrolling for anchor links
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            document.querySelector(this.getAttribute('href')).scrollIntoView({
                behavior: 'smooth'
            });
        });
    });

    // Mobile menu toggle
    const mobileMenuButton = document.getElementById('mobile-menu-button');
    const mobileMenu = document.getElementById('mobile-menu');
    
    if (mobileMenuButton && mobileMenu) {
        mobileMenuButton.addEventListener('click', function() {
            mobileMenu.classList.toggle('hidden');
        });
    }

    // Animation triggers
    const animateOnScroll = function() {
        const elements = document.querySelectorAll('.slide-up, .fade-in');
        
        elements.forEach(element => {
            const elementPosition = element.getBoundingClientRect().top;
            const screenPosition = window.innerHeight / 1.2;
            
            if (elementPosition < screenPosition) {
                element.style.opacity = '1';
                element.style.transform = 'translateY(0)';
            }
        });
    };

    // Set initial state for animated elements
    document.querySelectorAll('.slide-up').forEach(el => {
        el.style.opacity = '0';
        el.style.transform = 'translateY(20px)';
        el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
    });

    document.querySelectorAll('.fade-in').forEach(el => {
        el.style.opacity = '0';
        el.style.transition = 'opacity 0.5s ease';
    });

    // Run once on load
    animateOnScroll();
    
    // Run on scroll
    window.addEventListener('scroll', animateOnScroll);

    // Theme switcher (for future light/dark toggle)
    const themeToggle = document.getElementById('theme-toggle');
    if (themeToggle) {
        themeToggle.addEventListener('click', function() {
            document.documentElement.classList.toggle('dark');
            localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light');
        });
    }
});

// Dynamic agent terminal effect
const terminalLines = [
    { text: "$ agent create next.js e-commerce site", color: "text-green-400", delay: 1000 },
    { text: "β†’ Initializing project...", color: "text-gray-400", delay: 500 },
    { text: "β†’ Setting up Next.js with TypeScript", color: "text-gray-400", delay: 600 },
    { text: "β†’ Integrating Stripe payment system", color: "text-gray-400", delay: 700 },
    { text: "β†’ Generating product pages", color: "text-gray-400", delay: 600 },
    { text: "βœ“ Project ready at https://store.codegenius.dev", color: "text-green-400", delay: 800 }
];

function animateTerminal(terminalElement) {
    terminalElement.innerHTML = '';
    let cumulativeDelay = 0;
    
    terminalLines.forEach(line => {
        cumulativeDelay += line.delay;
        setTimeout(() => {
            const lineElement = document.createElement('div');
            lineElement.className = line.color;
            lineElement.textContent = line.text;
            terminalElement.appendChild(lineElement);
        }, cumulativeDelay);
    });
    
    // Restart animation after completion
    setTimeout(() => {
        terminalElement.innerHTML = '';
        animateTerminal(terminalElement);
    }, cumulativeDelay + 3000);
}

// Initialize terminal animation if element exists
const terminalElement = document.querySelector('.terminal-animation');
if (terminalElement) {
    animateTerminal(terminalElement);
}