File size: 6,432 Bytes
bcb835b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c685419
bcb835b
c685419
bcb835b
 
c685419
 
 
 
 
 
bcb835b
 
 
 
 
 
 
c685419
 
 
 
 
 
bcb835b
c685419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bcb835b
c685419
 
 
 
 
bcb835b
c685419
 
 
bcb835b
c685419
 
 
 
bcb835b
c685419
 
bcb835b
c685419
 
bcb835b
 
 
 
 
 
 
 
 
 
c685419
 
 
bcb835b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c685419
 
 
 
 
 
 
 
 
81ca604
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

// Enhanced smooth scrolling for anchor links
document.addEventListener('DOMContentLoaded', () => {
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const target = document.querySelector(this.getAttribute('href'));
            if (target) {
                const headerHeight = 80; // Adjust based on your navbar height
                const targetPosition = target.getBoundingClientRect().top + window.pageYOffset - headerHeight;
                
                window.scrollTo({
                    top: targetPosition,
                    behavior: 'smooth'
                });
            }
        });
    });
// Enhanced Intersection Observer for animations
const observerOptions = {
    threshold: 0.05,
    rootMargin: '0px 0px -100px 0px'
};

const observer = new IntersectionObserver((entries) => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.classList.add('animate-fade-in');
            // Add stagger animation for child elements
            if (entry.target.classList.contains('stagger-animation')) {
                const children = entry.target.children;
                Array.from(children).forEach((child, index) => {
                    child.style.animationDelay = `${index * 0.1}s`;
                });
            }
        }
    });
}, observerOptions);

// Observe elements for animation
document.addEventListener('DOMContentLoaded', () => {
    const animatedElements = document.querySelectorAll('.service-card, .portfolio-item, .contact-form');
    animatedElements.forEach(el => {
        observer.observe(el);
    });
});
// Form handling
document.addEventListener('DOMContentLoaded', () => {
    const contactForm = document.querySelector('form');
    if (contactForm) {
        contactForm.addEventListener('submit', (e) => {
            e.preventDefault();
            
            // Get form data
            const formData = new FormData(contactForm);
            const data = Object.fromEntries(formData);
            
            // Simulate form submission
            const submitBtn = contactForm.querySelector('button[type="submit"]');
            const originalText = submitBtn.innerHTML;
            
            submitBtn.innerHTML = 'Sending...';
            submitBtn.disabled = true;
            
            // Simulate API call
            setTimeout(() => {
                submitBtn.innerHTML = 'Message Sent!';
                submitBtn.classList.remove('bg-gradient-to-r', 'from-primary-500', 'to-secondary-500');
                submitBtn.classList.add('bg-green-500');
                
                // Reset form
                contactForm.reset();
                
                // Reset button after 3 seconds
                setTimeout(() => {
                    submitBtn.innerHTML = originalText;
                    submitBtn.disabled = false;
                    submitBtn.classList.remove('bg-green-500');
                    submitBtn.classList.add('bg-gradient-to-r', 'from-primary-500', 'to-secondary-500');
                }, 3000);
            }, 1500);
        });
    }
});

// Theme toggle functionality (if needed for future light mode)
const themeToggle = {
    init() {
        this.toggleBtn = document.getElementById('theme-toggle');
        if (this.toggleBtn) {
            this.toggleBtn.addEventListener('click', () => {
                document.documentElement.classList.toggle('dark');
                localStorage.setItem('theme', document.documentElement.classList.contains('dark') ? 'dark' : 'light');
            });
        }
    }
};

// Initialize theme toggle
themeToggle.init();
// Enhanced fade-in animation class
const style = document.createElement('style');
style.textContent = `
    @keyframes fadeIn {
        from {
            opacity: 0;
            transform: translateY(40px) scale(0.95);
        }
        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }
    
    .animate-fade-in {
        animation: fadeIn 0.9s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    }
    
    .service-card, .portfolio-item, .contact-form {
        opacity: 0;
    }
    
    /* Magnetic button effect implementation */
    .magnetic-area {
        position: relative;
        display: inline-block;
    }
    
    .magnetic-btn {
        transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }
`;
document.head.appendChild(style);

// Magnetic button effect
class MagneticButton {
    constructor(element) {
        this.element = element;
        this.area = element.parentElement;
        this.bounding = this.area.getBoundingClientRect();
        this.area.addEventListener('mousemove', this.handleMouseMove.bind(this));
        this.area.addEventListener('mouseleave', this.handleMouseLeave.bind(this));
    }
    
    handleMouseMove(e) {
        const x = e.clientX - this.bounding.left - this.bounding.width / 2;
        const y = e.clientY - this.bounding.top - this.bounding.height / 2;
        
        const strength = 20;
        const newX = (x / this.bounding.width) * strength;
        const newY = (y / this.bounding.height) * strength;
        
        this.element.style.transform = `translate(${newX}px, ${newY}px) scale(1.05)`;
    }
    
    handleMouseLeave() {
        this.element.style.transform = 'translate(0px, 0px) scale(1)`;
    }
}

// Initialize magnetic buttons
document.addEventListener('DOMContentLoaded', () => {
    const magneticButtons = document.querySelectorAll('.magnetic-btn');
    magneticButtons.forEach(btn => {
        new MagneticButton(btn);
    });
});

// Enhanced parallax effect
window.addEventListener('scroll', () => {
    const scrolled = window.pageYOffset;
    const parallaxElements = document.querySelectorAll('.parallax');
    
    parallaxElements.forEach(element => {
        const speed = element.dataset.speed || 0.3;
        element.style.transform = `translateY(${scrolled * speed}px)`;
    });
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
    const scrolled = window.pageYOffset;
    const parallaxElements = document.querySelectorAll('.parallax');
    
    parallaxElements.forEach(element => {
        const speed = element.dataset.speed || 0.5;
        element.style.transform = `translateY(${scrolled * speed}px)`;
    });
});