File size: 2,643 Bytes
81fe900
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
```typescript
interface CustomElement extends HTMLElement {
    style: CSSStyleDeclaration;
}

document.addEventListener('DOMContentLoaded', (): void => {
    // Mobile menu toggle
    const mobileMenuButton: HTMLButtonElement | null = document.querySelector('button[class*="md:hidden"]');
    const navLinks: HTMLElement | null = document.querySelector('nav');
    
    if (mobileMenuButton && navLinks) {
        mobileMenuButton.addEventListener('click', (): void => {
            navLinks.classList.toggle('hidden');
            navLinks.classList.toggle('flex');
            navLinks.classList.toggle('flex-col');
            navLinks.classList.toggle('absolute');
            navLinks.classList.toggle('top-16');
            navLinks.classList.toggle('right-4');
            navLinks.classList.toggle('bg-gray-800');
            navLinks.classList.toggle('p-4');
            navLinks.classList.toggle('rounded-lg');
            navLinks.classList.toggle('shadow-xl');
        });
    }

    // Smooth scrolling for anchor links
    document.querySelectorAll('a[href^="#"]').forEach((anchor: HTMLAnchorElement): void => {
        anchor.addEventListener('click', function(e: MouseEvent): void {
            e.preventDefault();
            const href: string | null = this.getAttribute('href');
            if (href) {
                const target: HTMLElement | null = document.querySelector(href);
                if (target) {
                    target.scrollIntoView({
                        behavior: 'smooth'
                    });
                }
            }
        });
    });

    // Add floating animation to elements
    const floatingElements: NodeListOf<CustomElement> = document.querySelectorAll('.floating');
    floatingElements.forEach((el: CustomElement, index: number): void => {
        el.style.animationDelay = `${index * 0.5}s`;
    });

    // Dark mode toggle (optional)
    const darkModeToggle: HTMLButtonElement = document.createElement('button');
    darkModeToggle.innerHTML = '<i class="fas fa-moon"></i>';
    darkModeToggle.className = 'fixed bottom-4 right-4 bg-gray-800 p-3 rounded-full shadow-lg';
    document.body.appendChild(darkModeToggle);
    
    darkModeToggle.addEventListener('click', (): void => {
        document.body.classList.toggle('dark');
        const icon: HTMLElement | null = darkModeToggle.querySelector('i');
        if (icon) {
            if (document.body.classList.contains('dark')) {
                icon.classList.replace('fa-moon', 'fa-sun');
            } else {
                icon.classList.replace('fa-sun', 'fa-moon');
            }
        }
    });
});
```