CoolFace
Apppublic

WiktorWox/indiegameglobe-explorer

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
script.js62 linesDownload Raw Back to root
1document.addEventListener('DOMContentLoaded', function() {
2    // Smooth scrolling for anchor links
3    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
4        anchor.addEventListener('click', function (e) {
5            e.preventDefault();
6            document.querySelector(this.getAttribute('href')).scrollIntoView({
7                behavior: 'smooth'
8            });
9        });
10    });
11
12    // Mobile menu toggle functionality (will be used by navbar component)
13    window.toggleMobileMenu = function() {
14        const menu = document.getElementById('mobile-menu');
15        menu.classList.toggle('hidden');
16    };
17
18    // Intersection Observer for animations
19    const observerOptions = {
20        threshold: 0.1
21    };
22
23    const observer = new IntersectionObserver((entries) => {
24        entries.forEach(entry => {
25            if (entry.isIntersecting) {
26                entry.target.classList.add('animate-fadeIn');
27                observer.unobserve(entry.target);
28            }
29        });
30    }, observerOptions);
31
32    document.querySelectorAll('.animate-on-scroll').forEach(section => {
33        observer.observe(section);
34    });
35});
36
37// Form submission handler
38function handleSubmit(event) {
39    event.preventDefault();
40    const form = event.target;
41    const formData = new FormData(form);
42
43    fetch(form.action, {
44        method: 'POST',
45        body: formData,
46        headers: {
47            'Accept': 'application/json'
48        }
49    })
50    .then(response => {
51        if (response.ok) {
52            alert('Message sent successfully!');
53            form.reset();
54        } else {
55            throw new Error('Network response was not ok');
56        }
57    })
58    .catch(error => {
59        alert('There was a problem sending your message. Please try again later.');
60        console.error('Error:', error);
61    });
62}